/// <summary> /// Inflates or deflates a rectangle based on the margins for the current part. /// </summary> /// <param name="state">The theme state constant for which the margins are defined.</param> /// <param name="bounds">The rectangle to adjust.</param> /// <param name="margin">One of the <see cref="ThemeMargin"/> constants, which determines the margins to use.</param> /// <returns></returns> public Rectangle AdjustRectangle(int state, Rectangle bounds, ThemeMargin margin) { if (Supported) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT prc = new ThemeInternal.RECT(bounds); int [] margins = new int[4]; if (ThemeInternal.UxTheme.GetThemeMargins(theme.Handle, IntPtr.Zero, this.PartID, state, (int)margin, ref prc, margins) == 0) return Rectangle.FromLTRB( bounds.X + margins[0], bounds.Y + margins[2], bounds.Right - margins[1], bounds.Bottom - margins[3] ); } } } return bounds; }
/// <summary> /// Returns the content area for the background of the current part. /// </summary> /// <param name="hdc">The GDI device context to use.</param> /// <param name="state">The state of the part.</param> /// <param name="bounds">A <see cref="Rectangle"/> which contains the entire background area of the part.</param> /// <returns></returns> public Rectangle GetBackgroundContentRectangle(IntPtr hdc, int state, Rectangle bounds) { if (Supported) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT rcBounds = new ThemeInternal.RECT(bounds); ThemeInternal.RECT rcContent; if (ThemeInternal.UxTheme.GetThemeBackgroundContentRect(theme.Handle, hdc, this.PartID, state, ref rcBounds, out rcContent) == 0) return rcContent.ToRectangle(); } } } return bounds; }
/// <summary> /// Returns an <see cref="Int32"/> metric value defined by the part associated with the renderer. /// </summary> /// <param name="state">The theme state constant for which the metric is defined.</param> /// <param name="metric">One of the <see cref="ThemeMetric"/> constants, which determines the metric to return.</param> /// <returns></returns> public int GetMetric(int state, ThemeMetric metric) { if (Supported) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { int result; if (ThemeInternal.UxTheme.GetThemeMetric(theme.Handle, IntPtr.Zero, this.PartID, state, (int)metric, out result) == 0) return result; } } } return 0; }
/// <summary> /// Returns the value of a file name property defined by the part associated with the renderer. /// </summary> /// <param name="state">The theme state constant for which the filename is defined.</param> /// <param name="filename">One of the <see cref="ThemeFileName"/> constants, which determines the file name to return.</param> /// <returns></returns> public string GetFileName(int state, ThemeFileName filename) { if (Supported) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { int result = 0; string filenameString = new string((char)0, 128); if ((result = ThemeInternal.UxTheme.GetThemeFilename(theme.Handle, this.PartID, state, (int)filename, filenameString, 127)) == 0) { return filenameString.Substring(0, filenameString.IndexOf((char)0)); } } } } return null; }
private Color GetColorCore(int state, int colorConstant) { int result; if (Supported) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { if (ThemeInternal.UxTheme.GetThemeColor(theme.Handle, this.PartID, state, colorConstant, out result) == 0) return ColorTranslator.FromWin32(result); } } } return Color.Red; }
/// <summary> /// Draws text onto a GDI device context within the specified bounding rectangle, with the option of displaying disabled text /// and applying other text formatting. /// </summary> /// <param name="hdc">The GDI device context on which the text is drawn.</param> /// <param name="state">The theme state constant for which the text is drawn.</param> /// <param name="bounds">The bounding rectangle in which the text is drawn.</param> /// <param name="text">The text to draw.</param> /// <param name="disabled">True if the text should be drawn disabled; otherwise, false, and the text is drawn normally.</param> /// <param name="flags">A bitwise combination of the <see cref="ThemeTextFormatFlags"/> values.</param> public void DrawText(IntPtr hdc, int state, Rectangle bounds, string text, bool disabled, ThemeTextFormatFlags flags) { if (Supported && text != null && text.Length > 0 && hdc != IntPtr.Zero) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT prc = new ThemeInternal.RECT(bounds); ThemeInternal.UxTheme.DrawThemeText(theme.Handle, hdc, this.PartID, state, text, text.Length, (int)flags, disabled ? 1 : 0, ref prc); } } } }
/// <summary> /// Draws the part defined by the current renderer onto a specified device context, within the /// given clipping bounds, and using the specified <see cref="ThemeDrawFlags"/>. /// </summary> /// <param name="hdc">The GDI device context on which the part is drawn.</param> /// <param name="state">A constant which determines the current state of the part.</param> /// <param name="bounds">The bounding rectangle in which the part is drawn.</param> /// <param name="clipBounds">The bounding rectangle in which the part is clipped.</param> /// <param name="flags">A combination of <see cref="ThemeDrawFlags"/> which specify additional /// options used to draw the part.</param> public void Draw(IntPtr hdc, int state, Rectangle bounds, Rectangle clipBounds, ThemeDrawFlags flags) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { if ((flags & ThemeDrawFlags.UseDCOrigin) == ThemeDrawFlags.UseDCOrigin) { ThemeInternal.POINTAPI lpPoint; ThemeInternal.GetWindowOrgEx(hdc, out lpPoint); bounds.Offset(lpPoint.X*2, lpPoint.Y*2); clipBounds.Offset(lpPoint.X*2, lpPoint.Y*2); flags &= ~ThemeDrawFlags.UseDCOrigin; } ThemeInternal.RECT rect = new ThemeInternal.RECT(bounds); ThemeInternal.DTBGOPTS pOptions = new ThemeInternal.DTBGOPTS(); pOptions.dwSize = Marshal.SizeOf(typeof(ThemeInternal.DTBGOPTS)); pOptions.dwFlags = (int)flags; pOptions.rcClip = new ThemeInternal.RECT(clipBounds); ThemeInternal.UxTheme.DrawThemeBackgroundEx( theme.Handle, hdc, PartID, state, ref rect, ref pOptions); } } }
void DrawCore(IntPtr hdc, int state, Rectangle bounds, Rectangle clipBounds) { using (Htheme theme = new Htheme(this)) { if (theme.IsValid) { ThemeInternal.RECT rect = new ThemeInternal.RECT(bounds); ThemeInternal.RECT clipRect = new ThemeInternal.RECT(clipBounds); ThemeInternal.UxTheme.DrawThemeBackground( theme.Handle, hdc, PartID, state, ref rect, ref clipRect); } } }
/// <summary>Static initializer.</summary> static ThemeRenderer() { ClassNameCache = new ArrayList(); ClassNameCache.Add("Button"); ClassNameCache.Add("Clock"); ClassNameCache.Add("ComboBox"); ClassNameCache.Add("Edit"); ClassNameCache.Add("ExplorerBar"); ClassNameCache.Add("Header"); ClassNameCache.Add("ListView"); ClassNameCache.Add("Menu"); ClassNameCache.Add("MenuBand"); ClassNameCache.Add("Page"); ClassNameCache.Add("Progress"); ClassNameCache.Add("Rebar"); ClassNameCache.Add("Scrollbar"); ClassNameCache.Add("Spin"); ClassNameCache.Add("StartPanel"); ClassNameCache.Add("Status"); ClassNameCache.Add("Tab"); ClassNameCache.Add("TaskBand"); ClassNameCache.Add("TaskBar"); ClassNameCache.Add("Toolbar"); ClassNameCache.Add("Tooltip"); ClassNameCache.Add("Trackbar"); ClassNameCache.Add("TrayNotify"); ClassNameCache.Add("Treeview"); ClassNameCache.Add("Window"); ApplicationNameCache = new ArrayList(); ApplicationNameCache.Add("ExplorerBar"); ApplicationNameCache.Add("PlacesBar"); ApplicationNameCache.Add("Start"); ApplicationNameCache.Add("StartMenu"); ApplicationNameCache.Add("TaskBand"); ApplicationNameCache.Add("TaskBandGroupMenu"); ApplicationNameCache.Add("TaskBandVert"); ApplicationNameCache.Add("TaskBar"); ApplicationNameCache.Add("TaskBarVert"); ApplicationNameCache.Add("TrayNotify"); ApplicationNameCache.Add("TrayNotifyHoriz"); ApplicationNameCache.Add("TrayNotifyHorizOpen"); ApplicationNameCache.Add("TrayNotifyVert"); ApplicationNameCache.Add("TrayNotifyVertOpen"); ApplicationNameCache.Add("Shell"); HthemeCache = new Htheme[ClassNameCache.Count]; }