예제 #1
0
        public static void DrawThemeTextActive(
            Graphics aGraph,
            string aText,
            Point aLocation,
            SUxTextProperties aProp
            )
        {
            IntPtr lPriHdc = aGraph.GetHdc();
            VisualStyleRenderer lRenderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
            DTTOPTS             lOpts     = new DTTOPTS();

            lOpts.dwSize    = Marshal.SizeOf(lOpts);
            lOpts.dwFlags   = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
            lOpts.crText    = ColorTranslator.ToWin32(aProp.color);
            lOpts.iGlowSize = aProp.glowSize;
            RECT ltBounds = new RECT(0, 0, aProp.bounds.Width, aProp.bounds.Height);

            DrawThemeTextEx(
                lRenderer.Handle,
                lPriHdc,
                0, 0,
                aText,
                -1,
                (int)(aProp.flags),
                ref ltBounds,
                ref lOpts
                );
        }
예제 #2
0
 private static void DrawOnHDC(IntPtr compatHdc, string text, Font font, Padding internalBounds, Rectangle bounds, Color color, TextFormatFlags formatFlags, AeroLabelMode mode, IThemeTextOption[] options)
 {
     if (SystemSupports.IsAeroSupport && mode == AeroLabelMode.Aero)
     {
         IntPtr hFont = font.ToHfont();
         NativeMethod.SelectObject(compatHdc, hFont);
         VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
         DTTOPTS             dttOpts  = default(DTTOPTS);
         dttOpts.dwSize  = Marshal.SizeOf(dttOpts);
         dttOpts.dwFlags = (DTTOPSFlags)8193;
         dttOpts.crText  = ColorTranslator.ToWin32(color);
         for (int i = 0; i < options.Length; i++)
         {
             IThemeTextOption op = options[i];
             op.Apply(ref dttOpts);
         }
         RECT RECT = new RECT(internalBounds.Left, internalBounds.Top, bounds.Width - internalBounds.Right, bounds.Height - internalBounds.Bottom);
         int  ret  = NativeMethod.DrawThemeTextEx(renderer.Handle, compatHdc, 0, 0, text, -1, (int)formatFlags, ref RECT, ref dttOpts);
         if (ret != 0)
         {
             Marshal.ThrowExceptionForHR(ret);
         }
         NativeMethod.DeleteObject(hFont);
     }
     else
     {
         Graphics gc = Graphics.FromHdc(compatHdc);
         gc.TextRenderingHint = TextRenderingHint.AntiAlias;
         using (SolidBrush sb = new SolidBrush(Color.FromArgb(254, color)))
             gc.DrawString(text, font, sb, bounds);
     }
 }
        /// <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);
                }
            }
                        );
        }
예제 #4
0
        internal override void Apply(ref DTTOPTS options)
        {
            options.dwFlags       |= (DTTOPSFlags)28;
            options.crShadow       = ColorTranslator.ToWin32(this.Color);
            options.ptShadowOffset = new POINT(this.Offset);
            switch (this.Type)
            {
            case ShadowOption.ShadowType.None:
            {
                options.iTextShadowType = 0;
                return;
            }

            case ShadowOption.ShadowType.Single:
            {
                options.iTextShadowType = 1;
                return;
            }

            case ShadowOption.ShadowType.Continuous:
            {
                options.iTextShadowType = 2;
                return;
            }

            default:
            {
                return;
            }
            }
        }
예제 #5
0
 public static void DrawThemeTextActive(
     Graphics aGraph,
     string aText,
     Point aLocation,
     SUxTextProperties aProp
     )
 {
     IntPtr lPriHdc = aGraph.GetHdc();
     VisualStyleRenderer lRenderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
     DTTOPTS lOpts = new DTTOPTS();
     lOpts.dwSize = Marshal.SizeOf(lOpts);
     lOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
     lOpts.crText = ColorTranslator.ToWin32(aProp.color);
     lOpts.iGlowSize = aProp.glowSize;
     RECT ltBounds = new RECT(0, 0, aProp.bounds.Width, aProp.bounds.Height);
     DrawThemeTextEx(
                 lRenderer.Handle,
                 lPriHdc,
                 0, 0,
                 aText,
                 -1,
                 (int)(aProp.flags),
                 ref ltBounds,
                 ref lOpts
             );
 }
예제 #6
0
        public static void DrawText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags, TextStyle textStyle)
        {
            IntPtr primaryHdc = graphics.GetHdc();

            // Create a memory DC so we can work offscreen
            IntPtr memoryHdc = GDI32.CreateCompatibleDC(primaryHdc);

            // Create a device-independent bitmap and select it into our DC
            BITMAPINFO info = new BITMAPINFO();

            info.biSize        = Marshal.SizeOf(info);
            info.biWidth       = bounds.Width;
            info.biHeight      = -bounds.Height;
            info.biPlanes      = 1;
            info.biBitCount    = 32;
            info.biCompression = 0; // BI_RGB
            IntPtr dib = GDI32.CreateDIBSection(primaryHdc, info, 0, 0, IntPtr.Zero, 0);

            GDI32.SelectObject(memoryHdc, dib);

            // Create and select font
            IntPtr fontHandle = font.ToHfont();

            GDI32.SelectObject(memoryHdc, fontHandle);

            // Draw glowing text
            VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
            DTTOPTS             dttOpts  = new DTTOPTS {
                dwSize = Marshal.SizeOf(typeof(DTTOPTS))
            };

            if (textStyle == TextStyle.Glowing)
            {
                dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
            }
            else
            {
                dttOpts.dwFlags = DTT_COMPOSITED | DTT_TEXTCOLOR;
            }
            dttOpts.crText    = ColorTranslator.ToWin32(color);
            dttOpts.iGlowSize = 8; // This is about the size Microsoft Word 2007 uses

            RECT textBounds = new RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);

            DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts);

            // Copy to foreground
            const int SRCCOPY = 0x00CC0020;

            GDI32.BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY);

            // Clean up
            GDI32.DeleteObject(fontHandle);
            GDI32.DeleteObject(dib);
            GDI32.DeleteDC(memoryHdc);

            graphics.ReleaseHdc(primaryHdc);
        }
예제 #7
0
        public static void DrawText(Graphics graphics, string text, Font font, Rectangle bounds, Color color, TextFormatFlags flags, TextStyle textStyle)
        {
            if (!VisualStyleRenderer.IsSupported) {
                TextRenderer.DrawText(graphics, text, font, bounds, color, flags);
                return;
            }

            IntPtr primaryHdc = graphics.GetHdc();

            // Create a memory DC so we can work offscreen
            IntPtr memoryHdc = CreateCompatibleDC(primaryHdc);

            // Create a device-independent bitmap and select it into our DC
            BITMAPINFO info = new BITMAPINFO();
            info.biSize = Marshal.SizeOf(info);
            info.biWidth = bounds.Width;
            info.biHeight = -bounds.Height;
            info.biPlanes = 1;
            info.biBitCount = 32;
            info.biCompression = 0; // BI_RGB
            IntPtr dib = CreateDIBSection(primaryHdc, info, 0, 0, IntPtr.Zero, 0);
            SelectObject(memoryHdc, dib);

            // Create and select font
            IntPtr fontHandle = font.ToHfont();
            SelectObject(memoryHdc, fontHandle);

            // Draw glowing text
            VisualStyleRenderer renderer = new VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
            DTTOPTS dttOpts = new DTTOPTS();
            dttOpts.dwSize = Marshal.SizeOf(typeof(DTTOPTS));

            if (textStyle == TextStyle.Glowing) {
                dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
            }
            else {
                dttOpts.dwFlags = DTT_COMPOSITED | DTT_TEXTCOLOR;
            }
            dttOpts.crText = ColorTranslator.ToWin32(color);
            dttOpts.iGlowSize = 8; // This is about the size Microsoft Word 2007 uses
            RECT textBounds = new RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
            DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts);

            // Copy to foreground
            const int SRCCOPY = 0x00CC0020;
            BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY);

            // Clean up
            DeleteObject(fontHandle);
            DeleteObject(dib);
            DeleteDC(memoryHdc);

            graphics.ReleaseHdc(primaryHdc);
        }
예제 #8
0
 public static extern int DrawThemeTextEx(
     IntPtr hTheme,
     IntPtr hdc,
     int iPartId,
     int iStateId,
     string text,
     int iCharCount,
     int dwFlags,
     ref RECT pRect,
     ref DTTOPTS pOptions
     );
예제 #9
0
 public static void DrawText(IDeviceContext dc, String text, Rectangle bounds, TextFormatFlags format)
 {
     try
     {
         var options = new DTTOPTS();
         NativeMethods.DrawThemeTextEx(Renderer.Handle, dc.GetHdc(), 0, 0, text, text.Length, format, RECT.FromRectangle(bounds), options);
     }
     finally
     {
         dc.ReleaseHdc();
     }
 }
예제 #10
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="System.Drawing.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 SafeHTHEME(rnd.Handle, false);

            using (var hdc = new SafeTempHDC(dc))
                DrawThemeTextEx(ht, hdc, rnd.Part, rnd.State, text, text.Length, FromTFF(flags), ref rc, options);
            bounds = rc;
        }
예제 #11
0
        private void DrawTextOnGlassInternal(IntPtr destdc, String text, Font font, Rectangle ctlrct, ContentAlignment textAlign, int iglowSize)
        {
            if (Glass.IsDesktopCompositionEnabled())
            {
                RECT rc  = new RECT();
                RECT rc2 = new RECT();

                var iglowExpand = (int)(iglowSize * 0.5);
                //iglowExpand = 0;

                //make it larger to contain the glow effect
                rc.left   = ctlrct.Left - iglowExpand;
                rc.right  = ctlrct.Right;// + iglowExpand;
                rc.top    = ctlrct.Top - iglowExpand;
                rc.bottom = ctlrct.Bottom + iglowExpand;

                //Just the same rect with rc,but (0,0) at the lefttop
                rc2.left   = iglowExpand;
                rc2.top    = iglowExpand;
                rc2.right  = rc.right - rc.left;// - iglowExpand;
                rc2.bottom = rc.bottom - rc.top - iglowExpand;

                IntPtr Memdc = CreateCompatibleDC(destdc);   // Set up a memory DC where we'll draw the text.
                IntPtr bitmap;
                IntPtr bitmapOld = IntPtr.Zero;
                IntPtr logfnotOld;

                //int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;   //text format
                TextFormatFlags uFormat = TextFormatFlags.NoPrefix;   //text format
                //if ((textAlign == ContentAlignment.TopCenter) ||
                //    (textAlign == ContentAlignment.MiddleCenter) ||
                //    (textAlign == ContentAlignment.BottomCenter))
                //    uFormat |= TextFormatFlags.HorizontalCenter;

                //if ((textAlign == ContentAlignment.TopRight) ||
                //    (textAlign == ContentAlignment.MiddleRight) ||
                //    (textAlign == ContentAlignment.BottomRight))
                //    uFormat |= TextFormatFlags.Right;

                //if ((textAlign == ContentAlignment.MiddleLeft) ||
                //    (textAlign == ContentAlignment.MiddleCenter) ||
                //    (textAlign == ContentAlignment.MiddleRight))
                //    uFormat |= TextFormatFlags.VerticalCenter;

                //if ((textAlign == ContentAlignment.BottomLeft) ||
                //    (textAlign == ContentAlignment.BottomCenter) ||
                //    (textAlign == ContentAlignment.BottomRight))
                //    uFormat |= TextFormatFlags.Bottom;

                BITMAPINFO dib = new BITMAPINFO();
                dib.bmiHeader.biHeight      = -(rc.bottom - rc.top);    // negative because DrawThemeTextEx() uses a top-down DIB
                dib.bmiHeader.biWidth       = rc.right - rc.left;
                dib.bmiHeader.biPlanes      = 1;
                dib.bmiHeader.biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                dib.bmiHeader.biBitCount    = 32;
                dib.bmiHeader.biCompression = BI_RGB;
                if (!(SaveDC(Memdc) == 0))
                {
                    bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);   // Create a 32-bit bmp for use in offscreen drawing when glass is on
                    if (!(bitmap == IntPtr.Zero))
                    {
                        bitmapOld = SelectObject(Memdc, bitmap);
                        IntPtr hFont = font.ToHfont();
                        logfnotOld = SelectObject(Memdc, hFont);
                        try
                        {
                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);

                            DTTOPTS dttOpts = new DTTOPTS();
                            dttOpts.dwSize    = (uint)Marshal.SizeOf(typeof(DTTOPTS));
                            dttOpts.dwFlags   = DTT_COMPOSITED | DTT_GLOWSIZE;
                            dttOpts.iGlowSize = iglowSize;

                            DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, (int)uFormat, ref rc2, ref dttOpts);

                            BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.Message);
                        }

                        //using (var image = GetImageFromHBitmap(bitmap))
                        //{
                        //    image.Save(@"d:\temp\sqlupdate.png", System.Drawing.Imaging.ImageFormat.Png);
                        //}

                        //Remember to clean up
                        SelectObject(Memdc, bitmapOld);
                        SelectObject(Memdc, logfnotOld);
                        DeleteObject(bitmap);
                        DeleteObject(hFont);

                        ReleaseDC(Memdc, -1);
                        DeleteDC(Memdc);
                    }
                }
            }
        }
예제 #12
0
        //Draw text on the glass surface
        public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize)
        {
            if (isGlassSupported())
            {
                RECT rc  = new RECT();
                RECT rc2 = new RECT();

                rc.left   = ctlrct.Left;
                rc.right  = ctlrct.Right;
                rc.top    = ctlrct.Top;
                rc.bottom = ctlrct.Bottom;

                rc2.left   = 6;
                rc2.top    = 5;
                rc2.right  = rc.right - rc.left;
                rc2.bottom = rc.bottom - rc.top;

                IntPtr destdc = GetDC(hwnd);
                IntPtr Memdc  = CreateCompatibleDC(destdc);
                IntPtr bitmap;
                IntPtr bitmapOld = IntPtr.Zero;
                IntPtr logfnotOld;

                int uFormat = DT_SINGLELINE | DT_NOPREFIX;

                BITMAPINFO dib = new BITMAPINFO();
                dib.bmiHeader.biHeight      = -(rc.bottom - rc.top);
                dib.bmiHeader.biWidth       = rc.right - rc.left;
                dib.bmiHeader.biPlanes      = 1;
                dib.bmiHeader.biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                dib.bmiHeader.biBitCount    = 32;
                dib.bmiHeader.biCompression = BI_RGB;
                if (!(SaveDC(Memdc) == 0))
                {
                    bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);
                    if (!(bitmap == IntPtr.Zero))
                    {
                        bitmapOld = SelectObject(Memdc, bitmap);
                        IntPtr hFont = font.ToHfont();
                        logfnotOld = SelectObject(Memdc, hFont);
                        try
                        {
                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                            DTTOPTS dttOpts = new DTTOPTS();
                            dttOpts.dwSize    = (uint)Marshal.SizeOf(typeof(DTTOPTS));
                            dttOpts.dwFlags   = DTT_COMPOSITED | DTT_GLOWSIZE;
                            dttOpts.iGlowSize = iglowSize;
                            DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);
                            BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }

                        SelectObject(Memdc, bitmapOld);
                        SelectObject(Memdc, logfnotOld);
                        DeleteObject(bitmap);
                        DeleteObject(hFont);

                        ReleaseDC(Memdc, -1);
                        DeleteDC(Memdc);
                    }
                }
            }
        }
예제 #13
0
        public static void DrawTextOnGlass(IntPtr hwnd, string text, Font font, Rectangle ctlrct, int iglowSize = 10)
        {
            if (!CanUseAero)
            {
                return;
            }

            RECT rc = new RECT()
            {
                Left   = ctlrct.Left,
                Right  = ctlrct.Right + 2 * iglowSize,
                Top    = ctlrct.Top,
                Bottom = ctlrct.Bottom + 2 * iglowSize,
            };

            RECT rc2 = new RECT()
            {
                Left   = 0,
                Top    = 0,
                Right  = rc.Right - rc.Left,
                Bottom = rc.Bottom - rc.Top
            };

            IntPtr destdc = GetDC(hwnd);
            IntPtr Memdc  = CreateCompatibleDC(destdc);
            IntPtr bitmap;
            IntPtr bitmapOld = IntPtr.Zero;
            IntPtr logfnotOld;

            int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;

            BITMAPINFO dib = new BITMAPINFO()
            {
                bmiHeader = new BITMAPINFOHEADER()
                {
                    biHeight      = -(rc.Bottom - rc.Top),
                    biWidth       = rc.Right - rc.Left,
                    biPlanes      = 1,
                    biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER)),
                    biBitCount    = 32,
                    biCompression = BI_RGB
                }
            };

            if (SaveDC(Memdc) != 0)
            {
                bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);     // Create a 32-bit bmp for use in offscreen drawing when glass is on
                if (bitmap != IntPtr.Zero)
                {
                    bitmapOld = SelectObject(Memdc, bitmap);
                    IntPtr hFont = font.ToHfont();
                    logfnotOld = SelectObject(Memdc, hFont);
                    try {
                        VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);

                        DTTOPTS dttOpts = new DTTOPTS()
                        {
                            dwSize    = ( uint )Marshal.SizeOf(typeof(DTTOPTS)),
                            dwFlags   = DTT_COMPOSITED | DTT_GLOWSIZE,
                            iGlowSize = iglowSize
                        };
                        DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);
                        BitBlt(destdc, rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top, Memdc, 0, 0, SOURCE_COPY);
                    }
                    catch (Exception e) {
                        Logger.LogError(e);
                    }

                    finally {
                        try {
                            SelectObject(Memdc, bitmapOld);
                            SelectObject(Memdc, logfnotOld);
                            DeleteObject(bitmap);
                            DeleteObject(hFont);

                            ReleaseDC(Memdc, -1);
                            DeleteDC(Memdc);
                        }
                        catch { }
                    }
                }
            }
        }
예제 #14
0
 public static extern void DrawThemeTextEx(IntPtr hTheme, SafeDeviceHandle hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref RECT pRect, ref DTTOPTS pOptions);
예제 #15
0
 public static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string pszText, int iCharCount, int dwTextFlags, ref RECT pRect, ref DTTOPTS options);
 private static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref RECT pRect, ref DTTOPTS pOptions);
예제 #17
0
 public void DrawTextEx(Graphics g, string text, Font font, Rectangle layoutRect, ThemePart part, ThemeState state, ThemeTextFormat format, DTTOPTS options)
 {
     InternalDrawTextEx(g, text, font, layoutRect, part, state, format, options);
 }
예제 #18
0
        private static void DrawTextOnGlass(IntPtr hDC, string text, Font font, Rectangle rct, int iGlowSize, StringAlignment horizontalAlign)
        {
            RECT rect  = new RECT();
            RECT pRect = new RECT();

            rect.left    = rct.Left;
            rect.right   = rct.Right + (4 * iGlowSize);
            rect.top     = rct.Top;
            rect.bottom  = rct.Bottom + (2 * iGlowSize);
            pRect.left   = 2 * iGlowSize;
            pRect.top    = 2;
            pRect.right  = rect.Width - (3 * iGlowSize);
            pRect.bottom = rect.Height - 2;
            TextFormatFlags dwFlags = TextFormatFlags.ModifyString | TextFormatFlags.NoPrefix | TextFormatFlags.SingleLine;

            switch (horizontalAlign)
            {
            case StringAlignment.Near:
                dwFlags |= TextFormatFlags.EndEllipsis;
                break;

            case StringAlignment.Center:
                dwFlags |= TextFormatFlags.PathEllipsis | TextFormatFlags.HorizontalCenter;
                break;

            case StringAlignment.Far:
                dwFlags |= TextFormatFlags.Right;
                break;
            }
            IntPtr ptr = PInvoke.CreateCompatibleDC(hDC);

            if (ptr != IntPtr.Zero)
            {
                IntPtr     ptr5;
                BITMAPINFO pbmi = new BITMAPINFO();
                pbmi.bmiHeader.biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                pbmi.bmiHeader.biWidth       = rect.Width;
                pbmi.bmiHeader.biHeight      = -rect.Height;
                pbmi.bmiHeader.biPlanes      = 1;
                pbmi.bmiHeader.biBitCount    = 0x20;
                pbmi.bmiHeader.biCompression = 0;
                IntPtr hgdiobj = PInvoke.CreateDIBSection(ptr, ref pbmi, 0, out ptr5, IntPtr.Zero, 0);
                if (hgdiobj != IntPtr.Zero)
                {
                    IntPtr ptr3 = PInvoke.SelectObject(ptr, hgdiobj);
                    IntPtr ptr6 = font.ToHfont();
                    IntPtr ptr4 = PInvoke.SelectObject(ptr, ptr6);
                    VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
                    DTTOPTS             pOptions = new DTTOPTS();
                    pOptions.dwSize    = Marshal.SizeOf(typeof(DTTOPTS));
                    pOptions.dwFlags   = 0x2800;
                    pOptions.iGlowSize = iGlowSize;
                    PInvoke.DrawThemeTextEx(renderer.Handle, ptr, 0, 0, text, -1, dwFlags, ref pRect, ref pOptions);
                    PInvoke.BitBlt(hDC, rect.left, rect.top, rect.Width, rect.Height, ptr, 0, 0, 0xcc0020);
                    PInvoke.SelectObject(ptr, ptr3);
                    PInvoke.SelectObject(ptr, ptr4);
                    PInvoke.DeleteObject(hgdiobj);
                    PInvoke.DeleteObject(ptr6);
                }
                PInvoke.DeleteDC(ptr);
            }
        }
예제 #19
0
        //Draw text on the glass surface
        public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize)
        {
            if (isGlassSupported())
            {
                RECT rc = new RECT();
                RECT rc2 = new RECT();

                rc.left = ctlrct.Left;
                rc.right = ctlrct.Right;
                rc.top = ctlrct.Top;
                rc.bottom = ctlrct.Bottom;

                rc2.left = 6;
                rc2.top = 5;
                rc2.right = rc.right - rc.left;
                rc2.bottom = rc.bottom - rc.top;

                IntPtr destdc = GetDC(hwnd);
                IntPtr Memdc = CreateCompatibleDC(destdc);
                IntPtr bitmap;
                IntPtr bitmapOld = IntPtr.Zero;
                IntPtr logfnotOld;

                int uFormat = DT_SINGLELINE | DT_NOPREFIX;

                BITMAPINFO dib = new BITMAPINFO();
                dib.bmiHeader.biHeight = -(rc.bottom - rc.top);
                dib.bmiHeader.biWidth = rc.right - rc.left;
                dib.bmiHeader.biPlanes = 1;
                dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                dib.bmiHeader.biBitCount = 32;
                dib.bmiHeader.biCompression = BI_RGB;
                if (!(SaveDC(Memdc) == 0))
                {
                    bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);
                    if (!(bitmap == IntPtr.Zero))
                    {
                        bitmapOld = SelectObject(Memdc, bitmap);
                        IntPtr hFont = font.ToHfont();
                        logfnotOld = SelectObject(Memdc, hFont);
                        try
                        {
                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                            DTTOPTS dttOpts = new DTTOPTS();
                            dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS));
                            dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                            dttOpts.iGlowSize = iglowSize;
                            DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);
                            BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }

                        SelectObject(Memdc, bitmapOld);
                        SelectObject(Memdc, logfnotOld);
                        DeleteObject(bitmap);
                        DeleteObject(hFont);

                        ReleaseDC(Memdc, -1);
                        DeleteDC(Memdc);
                    }
                }
            }
        }
예제 #20
0
        protected virtual void InternalDrawTextEx(Graphics g, string text, Font font, Rectangle layoutRect, ThemePart part, ThemeState state, ThemeTextFormat format, DTTOPTS options)
        {
            RECT rDraw=new RECT(layoutRect);
			IntPtr hdc=g.GetHdc();
			IntPtr hFont=font.ToHfont();
            IntPtr old=SelectObject(hdc,hFont);
			//int hresult=DrawThemeText(m_hTheme,hdc,part.Value,state.Value,text,text.Length,(int)format,(drawdisabled?1:0),ref rDraw);
            options.dwSize = Marshal.SizeOf(options);
            int hresult = DrawThemeTextEx(m_hTheme, hdc, part.Value, state.Value, text, text.Length, (int)format, ref rDraw, ref options);

			SelectObject(hdc,old);
            WinApi.DeleteObject(hFont);
			g.ReleaseHdc(hdc);
        }
예제 #21
0
 internal override void Apply(ref DTTOPTS options)
 {
     options.dwFlags      |= DTTOPSFlags.DTT_APPLYOVERLAY;
     options.fApplyOverlay = this.Enabled;
 }
예제 #22
0
        /// <summary>
        /// Draws theme text on glass.
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="text"></param>
        /// <param name="font"></param>
        /// <param name="bounds"></param>
        /// <param name="glowSize"></param>
        /// <remarks>This method is courtesy of 版权所有 (I hope the name's right)</remarks>
        public static void DrawTextOnGlass(Graphics graphics, String text, Font font, Rectangle bounds, int glowSize)
        {
            if (IsGlassEnabled)
            {
                IntPtr destdc = IntPtr.Zero;
                try
                {
                    destdc = graphics.GetHdc();
                    IntPtr Memdc = CreateCompatibleDC(destdc);   // Set up a memory DC where we'll draw the text.
                    IntPtr bitmap;
                    IntPtr bitmapOld = IntPtr.Zero;
                    IntPtr logfnotOld;

                    int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;   //text format

                    BITMAPINFO dib = new BITMAPINFO();
                    dib.bmiHeader.biHeight      = -bounds.Height;    // negative because DrawThemeTextEx() uses a top-down DIB
                    dib.bmiHeader.biWidth       = bounds.Width;
                    dib.bmiHeader.biPlanes      = 1;
                    dib.bmiHeader.biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                    dib.bmiHeader.biBitCount    = 32;
                    dib.bmiHeader.biCompression = BI_RGB;
                    if (!(SaveDC(Memdc) == 0))
                    {
                        bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, (IntPtr)0, IntPtr.Zero, 0);   // Create a 32-bit bmp for use in offscreen drawing when glass is on
                        if (!(bitmap == IntPtr.Zero))
                        {
                            bitmapOld = SelectObject(Memdc, bitmap);
                            IntPtr hFont = font.ToHfont();
                            logfnotOld = SelectObject(Memdc, hFont);
                            try
                            {
                                VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);

                                DTTOPTS dttOpts = new DTTOPTS
                                {
                                    dwSize    = (uint)Marshal.SizeOf(typeof(DTTOPTS)),
                                    dwFlags   = DTT_COMPOSITED | DTT_GLOWSIZE,
                                    iGlowSize = glowSize
                                };

                                RECT rc2   = new RECT(0, 0, bounds.Width, bounds.Height);
                                int  dtter = DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);
                                bool bbr   = BitBlt(destdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Memdc, 0, 0, SRCCOPY);
                                if (!bbr)
                                {
                                    //throw new Exception("???");
                                }
                            }
                            catch (Exception)
                            {
                                //Console.WriteLine(e.ToString());
                                //throw new Exception("???");
                            }

                            //Remember to clean up
                            SelectObject(Memdc, bitmapOld);
                            SelectObject(Memdc, logfnotOld);
                            DeleteObject(bitmap);
                            DeleteObject(hFont);

                            ReleaseDC(Memdc, (IntPtr)(-1));
                            DeleteDC(Memdc);
                        }
                    }
                }
                finally
                {
                    if (destdc != IntPtr.Zero)
                    {
                        graphics.ReleaseHdc(destdc);
                    }
                }
            }
        }
        /// <summary>
        /// Draws theme text on glass.
        /// </summary>
        /// <param name="hwnd"></param>
        /// <param name="text"></param>
        /// <param name="font"></param>
        /// <param name="bounds"></param>
        /// <param name="glowSize"></param>
        /// <remarks>This method is courtesy of 版权所有 (I hope the name's right)</remarks>
        public static void DrawTextOnGlass(Graphics graphics, String text, Font font, Rectangle bounds, int glowSize)
        {
            if (IsGlassEnabled)
            {
                IntPtr destdc = IntPtr.Zero;
                try
                {
                    destdc = graphics.GetHdc();
                    IntPtr Memdc = CreateCompatibleDC(destdc);   // Set up a memory DC where we'll draw the text.
                    IntPtr bitmap;
                    IntPtr bitmapOld = IntPtr.Zero;
                    IntPtr logfnotOld;

                    int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;   //text format

                    BITMAPINFO dib = new BITMAPINFO();
                    dib.bmiHeader.biHeight = -bounds.Height;         // negative because DrawThemeTextEx() uses a top-down DIB
                    dib.bmiHeader.biWidth = bounds.Width;
                    dib.bmiHeader.biPlanes = 1;
                    dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                    dib.bmiHeader.biBitCount = 32;
                    dib.bmiHeader.biCompression = BI_RGB;
                    if (!(SaveDC(Memdc) == 0))
                    {
                        bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);   // Create a 32-bit bmp for use in offscreen drawing when glass is on
                        if (!(bitmap == IntPtr.Zero))
                        {
                            bitmapOld = SelectObject(Memdc, bitmap);
                            IntPtr hFont = font.ToHfont();
                            logfnotOld = SelectObject(Memdc, hFont);
                            try
                            {

                                VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);

                                DTTOPTS dttOpts = new DTTOPTS();
                                dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS));
                                dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
                                dttOpts.iGlowSize = glowSize;

                                RECT rc2 = new RECT(0, 0, bounds.Width, bounds.Height);
                                int dtter = DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);
                                bool bbr = BitBlt(destdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, Memdc, 0, 0, SRCCOPY);
                                if (!bbr)
                                {
                                    //throw new Exception("???");
                                }
                            }
                            catch (Exception)
                            {
                                //Console.WriteLine(e.ToString());
                                //throw new Exception("???");
                            }

                            //Remember to clean up
                            SelectObject(Memdc, bitmapOld);
                            SelectObject(Memdc, logfnotOld);
                            DeleteObject(bitmap);
                            DeleteObject(hFont);

                            ReleaseDC(Memdc, -1);
                            DeleteDC(Memdc);
                        }
                        else
                        {
                            //throw new Exception("???");
                        }
                    }
                    else
                    {
                        //throw new Exception("???");
                    }
                }
                finally
                {
                    if (destdc != IntPtr.Zero)
                        graphics.ReleaseHdc(destdc);
                }
            }
        }
예제 #24
0
 public static extern void DrawThemeTextEx(IntPtr hTheme, SafeDeviceHandle hdc, int iPartId, int iStateId, string text, int iCharCount, int dwFlags, ref RECT pRect, ref DTTOPTS pOptions);
예제 #25
0
 internal override void Apply(ref DTTOPTS options)
 {
     options.dwFlags    |= (DTTOPSFlags)34;
     options.crBorder    = ColorTranslator.ToWin32(this.BorderColor);
     options.iBorderSize = this.BorderSize;
 }
        public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize)
        {
            if (IsCompositionEnabled())
            {
                RECT rc = new RECT();
                RECT rc2 = new RECT();

                rc.left = ctlrct.Left;
                rc.right = ctlrct.Right + 2 * iglowSize;  //make it larger to contain the glow effect
                rc.top = ctlrct.Top;
                rc.bottom = ctlrct.Bottom + 2 * iglowSize;

                //Just the same rect with rc,but (0,0) at the lefttop
                rc2.left = 0;
                rc2.top = 0;
                rc2.right = rc.right - rc.left;
                rc2.bottom = rc.bottom - rc.top;

                IntPtr destdc = GetDC(hwnd);    //hwnd must be the handle of form,not control
                IntPtr Memdc = CreateCompatibleDC(destdc);   // Set up a memory DC where we'll draw the text.
                IntPtr bitmap;
                IntPtr bitmapOld = IntPtr.Zero;
                IntPtr logfnotOld;

                int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;   //text format

                BITMAPINFO dib = new BITMAPINFO();
                dib.bmiHeader.biHeight = -(rc.bottom - rc.top);         // negative because DrawThemeTextEx() uses a top-down DIB
                dib.bmiHeader.biWidth = rc.right - rc.left;
                dib.bmiHeader.biPlanes = 1;
                dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                dib.bmiHeader.biBitCount = 32;
                dib.bmiHeader.biCompression = BI_RGB;
                if (!(SaveDC(Memdc) == 0))
                {
                    bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);   // Create a 32-bit bmp for use in offscreen drawing when glass is on
                    if (!(bitmap == IntPtr.Zero))
                    {
                        bitmapOld = SelectObject(Memdc, bitmap);
                        IntPtr hFont = font.ToHfont();
                        logfnotOld = SelectObject(Memdc, hFont);
                        try
                        {

                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);

                            DTTOPTS dttOpts = new DTTOPTS();

                            dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS));

                            dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;

                            dttOpts.iGlowSize = iglowSize;

                            DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);

                            BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);

                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.Message);
                        }

                        //Remember to clean up
                        SelectObject(Memdc, bitmapOld);
                        SelectObject(Memdc, logfnotOld);
                        DeleteObject(bitmap);
                        DeleteObject(hFont);

                        ReleaseDC(Memdc, -1);
                        DeleteDC(Memdc);

                    }

                }

            }
        }
예제 #27
0
 internal abstract void Apply(ref DTTOPTS options);
예제 #28
0
        public void DrawTextOnGlass(IntPtr hwnd, String text, Font font, Rectangle ctlrct, int iglowSize)
        {
            if (IsCompositionEnabled())
            {
                RECT rc  = new RECT();
                RECT rc2 = new RECT();

                rc.left   = ctlrct.Left;
                rc.right  = ctlrct.Right + 2 * iglowSize; //make it larger to contain the glow effect
                rc.top    = ctlrct.Top;
                rc.bottom = ctlrct.Bottom + 2 * iglowSize;

                //Just the same rect with rc,but (0,0) at the lefttop
                rc2.left   = 0;
                rc2.top    = 0;
                rc2.right  = rc.right - rc.left;
                rc2.bottom = rc.bottom - rc.top;

                IntPtr destdc = GetDC(hwnd);                //hwnd must be the handle of form,not control
                IntPtr Memdc  = CreateCompatibleDC(destdc); // Set up a memory DC where we'll draw the text.
                IntPtr bitmap;
                IntPtr bitmapOld = IntPtr.Zero;
                IntPtr logfnotOld;

                int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;   //text format

                BITMAPINFO dib = new BITMAPINFO();
                dib.bmiHeader.biHeight      = -(rc.bottom - rc.top);    // negative because DrawThemeTextEx() uses a top-down DIB
                dib.bmiHeader.biWidth       = rc.right - rc.left;
                dib.bmiHeader.biPlanes      = 1;
                dib.bmiHeader.biSize        = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
                dib.bmiHeader.biBitCount    = 32;
                dib.bmiHeader.biCompression = BI_RGB;
                if (!(SaveDC(Memdc) == 0))
                {
                    bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);   // Create a 32-bit bmp for use in offscreen drawing when glass is on
                    if (!(bitmap == IntPtr.Zero))
                    {
                        bitmapOld = SelectObject(Memdc, bitmap);
                        IntPtr hFont = font.ToHfont();
                        logfnotOld = SelectObject(Memdc, hFont);
                        try
                        {
                            System.Windows.Forms.VisualStyles.VisualStyleRenderer renderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);

                            DTTOPTS dttOpts = new DTTOPTS();

                            dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS));

                            dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;


                            dttOpts.iGlowSize = iglowSize;

                            DrawThemeTextEx(renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts);



                            BitBlt(destdc, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, Memdc, 0, 0, SRCCOPY);
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.Message);
                        }


                        //Remember to clean up
                        SelectObject(Memdc, bitmapOld);
                        SelectObject(Memdc, logfnotOld);
                        DeleteObject(bitmap);
                        DeleteObject(hFont);

                        ReleaseDC(Memdc, -1);
                        DeleteDC(Memdc);
                    }
                }
            }
        }
예제 #29
0
        public static void DrawTextOnGlass( IntPtr hwnd, string text, Font font, Rectangle ctlrct, int iglowSize = 10 ) {
            if ( !CanUseAero ) {
                return;
            }

            RECT rc = new RECT() {
                Left = ctlrct.Left,
                Right = ctlrct.Right + 2 * iglowSize,
                Top = ctlrct.Top,
                Bottom = ctlrct.Bottom + 2 * iglowSize,
            };

            RECT rc2 = new RECT() {
                Left = 0,
                Top = 0,
                Right = rc.Right - rc.Left,
                Bottom = rc.Bottom - rc.Top
            };

            IntPtr destdc = GetDC( hwnd );
            IntPtr Memdc = CreateCompatibleDC( destdc );
            IntPtr bitmap;
            IntPtr bitmapOld = IntPtr.Zero;
            IntPtr logfnotOld;

            int uFormat = DT_SINGLELINE | DT_CENTER | DT_VCENTER | DT_NOPREFIX;

            BITMAPINFO dib = new BITMAPINFO() {
                bmiHeader = new BITMAPINFOHEADER() {
                    biHeight = -( rc.Bottom - rc.Top ),
                    biWidth = rc.Right - rc.Left,
                    biPlanes = 1,
                    biSize = Marshal.SizeOf( typeof( BITMAPINFOHEADER ) ),
                    biBitCount = 32,
                    biCompression = BI_RGB
                }
            };

            if ( SaveDC( Memdc ) != 0 ) {
                bitmap = CreateDIBSection( Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0 );   // Create a 32-bit bmp for use in offscreen drawing when glass is on
                if ( bitmap != IntPtr.Zero ) {
                    bitmapOld = SelectObject( Memdc, bitmap );
                    IntPtr hFont = font.ToHfont();
                    logfnotOld = SelectObject( Memdc, hFont );
                    try {

                        VisualStyleRenderer renderer = new VisualStyleRenderer( VisualStyleElement.Window.Caption.Active );

                        DTTOPTS dttOpts = new DTTOPTS() {
                            dwSize = ( uint ) Marshal.SizeOf( typeof( DTTOPTS ) ),
                            dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE,
                            iGlowSize = iglowSize
                        };
                        DrawThemeTextEx( renderer.Handle, Memdc, 0, 0, text, -1, uFormat, ref rc2, ref dttOpts );
                        BitBlt( destdc, rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top, Memdc, 0, 0, SOURCE_COPY );
                    }
                    catch ( Exception e ) {
                        Logger.LogError( e );
                    }

                    finally {
                        try {
                            SelectObject( Memdc, bitmapOld );
                            SelectObject( Memdc, logfnotOld );
                            DeleteObject( bitmap );
                            DeleteObject( hFont );

                            ReleaseDC( Memdc, -1 );
                            DeleteDC( Memdc );
                        }
                        catch { }
                    }

                }

            }

        }
예제 #30
0
        public static void DrawTextOnGlass(Graphics graphics, string text, Font font, Rectangle bounds,
            Color color, TextFormatFlags flags, bool withGlow)
        {
            IntPtr primaryHdc = graphics.GetHdc();

              // Memory DC for off screen rendering.
              IntPtr memoryHdc = CreateCompatibleDC(primaryHdc);

              BITMAPINFO info = new BITMAPINFO();
              info.biSize = Marshal.SizeOf(info);
              info.biWidth = bounds.Width;
              info.biHeight = -bounds.Height;
              info.biPlanes = 1;
              info.biBitCount = 32;
              info.biCompression = 0; // BI_RGB
              IntPtr dib = CreateDIBSection(primaryHdc, info, 0, 0, IntPtr.Zero, 0);
              SelectObject(memoryHdc, dib);

              IntPtr fontHandle = font.ToHfont();
              SelectObject(memoryHdc, fontHandle);

              // Draw glowing text if enabled.
              VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active);
              DTTOPTS dttOpts = new DTTOPTS();
              dttOpts.dwSize = (uint)Marshal.SizeOf(typeof(DTTOPTS));

              if (withGlow)
              {
            dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
            dttOpts.iGlowSize = 12;
              }
              else
              {
            dttOpts.dwFlags = DTT_COMPOSITED | DTT_TEXTCOLOR;
            dttOpts.iGlowSize = 0;
              }
              dttOpts.crText = (uint)ColorTranslator.ToWin32(color);
              RECT textBounds = new RECT(dttOpts.iGlowSize, 0, bounds.Width - dttOpts.iGlowSize, bounds.Height);
              DrawThemeTextEx(renderer.Handle, memoryHdc, 0, 0, text, -1, (int)flags, ref textBounds, ref dttOpts);

              //const int SRCCOPY = 0x00CC0020;
              //BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, SRCCOPY);

              BLENDFUNCTION blend = new Win32.BLENDFUNCTION(AC_SRC_OVER, 0, 255, AC_SRC_ALPHA);
              AlphaBlend(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0,
            bounds.Width, bounds.Height, blend);

              // Clean up
              DeleteObject(fontHandle);
              DeleteObject(dib);
              DeleteDC(memoryHdc);

              graphics.ReleaseHdc(primaryHdc);
        }
예제 #31
0
 internal override void Apply(ref DTTOPTS options)
 {
     options.dwFlags  |= DTTOPSFlags.DTT_GLOWSIZE;
     options.iGlowSize = this.Size;
 }