コード例 #1
0
        /// <summary>
        /// Draws glowing text in the specified bounding rectangle with the option of overriding text color and applying other text formatting.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer" /> instance.</param>
        /// <param name="dc">The <see cref="IDeviceContext" /> used to draw the text.</param>
        /// <param name="bounds">A <see cref="Rectangle" /> in which the text is drawn.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="font">Optional font override.</param>
        /// <param name="color">Optionally, the color to draw text in overriding the default color for the theme.</param>
        /// <param name="flags">A bitwise combination of the <see cref="TextFormatFlags" /> values.</param>
        /// <param name="glowSize">The size of the glow.</param>
        public static void DrawGlowingText(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, string text, Font font, Color?color, TextFormatFlags flags = TextFormatFlags.Default, int glowSize = 10)
        {
            var ht = new SafeThemeHandle(rnd.Handle, false);

            DrawWrapper(dc, bounds,
                        memoryHdc =>
            {
                // Create and select font
                using (new SafeDCObjectHandle(memoryHdc, font?.ToHfont() ?? IntPtr.Zero))
                {
                    // Draw glowing text
                    var dttOpts = new DTTOPTS(null)
                    {
                        GlowSize = glowSize, AntiAliasedAlpha = true
                    };
                    if (color != null)
                    {
                        dttOpts.TextColor = color.Value;
                    }
                    var textBounds = new RECT(4, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
                    DrawThemeTextEx(ht, memoryHdc, rnd.Part, rnd.State, text, text.Length, FromTFF(flags), ref textBounds, ref dttOpts);
                }
            }
                        );
        }
コード例 #2
0
 public static int[] GetThemeIntList(SafeThemeHandle hTheme, int partId, int stateId, int propId)
 {
     if (Environment.OSVersion.Version.Major < 6)
     {
         INTLIST_OLD l;
         if (0 != GetThemeIntListPreVista(hTheme, partId, stateId, propId, out l))
         {
             return(null);
         }
         var outlist = new int[l.iValueCount];
         Array.Copy(l.iValues, outlist, l.iValueCount);
         return(outlist);
     }
     else
     {
         INTLIST l;
         if (0 != GetThemeIntList(hTheme, partId, stateId, propId, out l))
         {
             return(null);
         }
         var outlist = new int[l.iValueCount];
         Array.Copy(l.iValues, outlist, l.iValueCount);
         return(outlist);
     }
 }
コード例 #3
0
 public void _Setup()
 {
     hwt = OpenThemeDataEx(new HandleRef(), "Window", OpenThemeDataOptions.None);
     Assert.That(hwt.IsInvalid, Is.False);
     hbt = OpenThemeDataEx(new HandleRef(), "Button", OpenThemeDataOptions.None);
     Assert.That(hbt.IsInvalid, Is.False);
 }
コード例 #4
0
        /// <summary>
        /// Draws the background image of the current visual style element onto a glass background within the specified bounding rectangle and optionally clipped to the specified clipping rectangle.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
        /// <param name="dc">The <see cref="IDeviceContext"/> used to draw the background image.</param>
        /// <param name="bounds">A <see cref="Rectangle"/> in which the background image is drawn.</param>
        /// <param name="clipRectangle">A <see cref="Rectangle"/> that defines a clipping rectangle for the drawing operation.</param>
        /// <param name="rightToLeft">If set to <c>true</c> flip the image for right to left layout.</param>
        public static void DrawGlassBackground(this VisualStyleRenderer rnd, IDeviceContext dc, Rectangle bounds, Rectangle?clipRectangle = null, bool rightToLeft = false)
        {
            var ht = new SafeThemeHandle(rnd.Handle, false);

            DrawWrapper(dc, bounds,
                        memoryHdc =>
            {
                var rBounds = new RECT(bounds);
                //var opts = new DrawThemeBackgroundOptions(clipRectangle);
                // Draw background
                var oldLayout = DCLayout.GDI_ERROR;
                if (rightToLeft)
                {
                    if ((oldLayout = SetLayout(memoryHdc, DCLayout.LAYOUT_RTL)) == DCLayout.GDI_ERROR)
                    {
                        throw new NotSupportedException("Unable to change graphics layout to RTL.");
                    }
                }
                DrawThemeBackground(ht, memoryHdc, rnd.Part, rnd.State, ref rBounds, clipRectangle);
                if (oldLayout != DCLayout.GDI_ERROR)
                {
                    SetLayout(memoryHdc, oldLayout);
                }
            }
                        );
        }
コード例 #5
0
ファイル: UxTheme.cs プロジェクト: santoshmenon/pinvoke
 public static extern unsafe HResult GetThemeMargins(
     SafeThemeHandle hTheme,
     User32.SafeDCHandle hdc,
     int iPartId,
     int iStateId,
     int iPropId,
     [Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] RECT *prc,
     out MARGINS pMargins);
コード例 #6
0
        /// <summary>
        /// Draws text in the specified bounding rectangle with the option of applying other text formatting.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer" /> instance.</param>
        /// <param name="dc">The <see cref="IDeviceContext" /> used to draw the text.</param>
        /// <param name="bounds">A <see cref="Rectangle" /> in which the text is drawn.</param>
        /// <param name="text">The text to draw.</param>
        /// <param name="flags">A bitwise combination of the <see cref="TextFormatFlags"/> values.</param>
        /// <param name="options">The <see cref="DTTOPTS"/> .</param>
        public static void DrawText(this VisualStyleRenderer rnd, IDeviceContext dc, ref Rectangle bounds, string text, TextFormatFlags flags, ref DTTOPTS options)
        {
            var rc = new RECT(bounds);
            var ht = new SafeThemeHandle(rnd.Handle, false);

            using (var hdc = new SafeDCHandle(dc))
                DrawThemeTextEx(ht, hdc, rnd.Part, rnd.State, text, text.Length, FromTFF(flags), ref rc, ref options);
            bounds = rc;
        }
コード例 #7
0
        public VisualTheme(IWin32Window window, string classList, OpenThemeDataOptions opt = OpenThemeDataOptions.None)
        {
            var ptr = OpenThemeDataEx(new HandleRef(window, window?.Handle ?? IntPtr.Zero), classList, opt);

            hTheme = new SafeThemeHandle(ptr);
            if (hTheme.IsInvalid)
            {
                throw new Win32Exception();
            }
        }
コード例 #8
0
        /// <summary>
        /// Draws the image from the specified <paramref name="imageList"/> within the specified bounds on a glass background.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
        /// <param name="g">The <see cref="Graphics"/> used to draw the image.</param>
        /// <param name="bounds">A <see cref="Rectangle"/> in which the image is drawn.</param>
        /// <param name="imageList">An <see cref="ImageList"/> that contains the <see cref="Image"/> to draw.</param>
        /// <param name="imageIndex">The index of the <see cref="Image"/> within <paramref name="imageList"/> to draw.</param>
        public static void DrawGlassImage(this VisualStyleRenderer rnd, IDeviceContext g, Rectangle bounds, ImageList imageList, int imageIndex)
        {
            var ht = new SafeThemeHandle(rnd.Handle, false);

            DrawWrapper(g, bounds,
                        memoryHdc =>
            {
                var rBounds = new RECT(bounds);
                DrawThemeIcon(ht, memoryHdc, rnd.Part, rnd.State, ref rBounds, new System.Runtime.InteropServices.HandleRef(imageList, imageList.Handle), imageIndex);
            }
                        );
        }
コード例 #9
0
        /// <summary>
        /// Draws the image from the specified <paramref name="imageList"/> within the specified bounds on a glass background.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
        /// <param name="g">The <see cref="Graphics"/> used to draw the image.</param>
        /// <param name="bounds">A <see cref="Rectangle"/> in which the image is drawn.</param>
        /// <param name="imageList">An <see cref="ImageList"/> that contains the <see cref="Image"/> to draw.</param>
        /// <param name="imageIndex">The index of the <see cref="Image"/> within <paramref name="imageList"/> to draw.</param>
        public static void DrawGlassImage(this VisualStyleRenderer rnd, Graphics g, Rectangle bounds, ImageList imageList, int imageIndex)
        {
            var ht = new SafeThemeHandle(rnd.Handle, false);

            DrawWrapper(g, bounds,
                        memoryHdc =>
            {
                var rBounds = new RECT(bounds);
                DrawThemeIcon(ht, memoryHdc, rnd.Part, rnd.State, ref rBounds, imageList.Handle, imageIndex);
            }
                        );
        }
コード例 #10
0
        internal static void DrawGlassBackground(SafeThemeHandle hTheme, SafeDCHandle memoryHdc, int part, int state, Rectangle bounds, bool rightToLeft, Rectangle?clipRectangle)
        {
            var rBounds = new RECT(bounds);
            //var opts = new DrawThemeBackgroundOptions(clipRectangle);
            // Draw background
            var oldLayout = DCLayout.GDI_ERROR;

            if (rightToLeft)
            {
                if ((oldLayout = SetLayout(memoryHdc, DCLayout.LAYOUT_RTL)) == DCLayout.GDI_ERROR)
                {
                    throw new NotSupportedException("Unable to change graphics layout to RTL.");
                }
            }
            DrawThemeBackground(hTheme, memoryHdc, part, state, ref rBounds, clipRectangle);
            if (oldLayout != DCLayout.GDI_ERROR)
            {
                SetLayout(memoryHdc, oldLayout);
            }
        }
コード例 #11
0
 public static extern int GetThemeString(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, ref System.Text.StringBuilder themeString, int themeStringLength);
コード例 #12
0
 public static extern int GetThemeStream(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 5)] out byte[] pvStream, out int cbStream, IntPtr hInst);
コード例 #13
0
 public static extern int GetThemeRect(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out RECT pRect);
コード例 #14
0
 public static extern int GetThemePropertyOrigin(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out ThemePropertyOrigin pOrigin);
コード例 #15
0
 public static extern int GetThemePosition(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out Point piVal);
コード例 #16
0
 public static extern int GetThemeBitmap(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, int dwFlags, out IntPtr phBitmap);
コード例 #17
0
 public static extern int GetThemeTransitionDuration(SafeThemeHandle hTheme, int iPartId, int iStateIdFrom, int iStateIdTo, int iPropId, out int pdwDuration);
コード例 #18
0
 public static extern int GetThemeInt(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int piVal);
コード例 #19
0
 public static extern bool IsThemePartDefined(SafeThemeHandle hTheme, int iPartId, int iStateId);
コード例 #20
0
 public static extern int GetThemeFilename(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, ref System.Text.StringBuilder pszBuff, int buffLength);
コード例 #21
0
 public static extern int GetThemeColor(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out int pColor);
コード例 #22
0
 public static extern int GetThemeBool(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, [MarshalAs(UnmanagedType.Bool)] out bool pfVal);
コード例 #23
0
 public static extern int GetThemeSysInt(SafeThemeHandle hTheme, int iIntID, out int piVal);
コード例 #24
0
 public static extern int GetThemeMetric(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, out int piVal);
コード例 #25
0
 public static extern int GetThemeTextExtent(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, string text, int textLength, TextFormatFlags textFlags, ref RECT boundingRect, out RECT extentRect);
コード例 #26
0
 public static extern int GetThemePartSize(SafeThemeHandle hTheme, SafeDCHandle hdc, int part, int state, PRECT pRect, ThemeSize eSize, out Size size);
コード例 #27
0
 public static extern bool IsThemeBackgroundPartiallyTransparent(SafeThemeHandle hTheme, int iPartId, int iStateId);
コード例 #28
0
 public static extern int GetThemeBackgroundContentRect(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, ref RECT pBoundingRect, out RECT pContentRect);
コード例 #29
0
 private static extern int GetThemeIntListPreVista(SafeThemeHandle hTheme, int iPartId, int iStateId, int iPropId, out INTLIST_OLD pIntList);
コード例 #30
0
 public static extern int GetThemeMargins(SafeThemeHandle hTheme, SafeDCHandle hdc, int iPartId, int iStateId, int iPropId, IntPtr prc, out RECT pMargins);