Example #1
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);
            }
        }
Example #2
0
 public static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, TextFormatFlags dwFlags, ref RECT pRect, ref DTTOPTS pOptions);
Example #3
0
 public static extern int DrawThemeTextEx(IntPtr hTheme, IntPtr hdc, int iPartId, int iStateId, string text, int iCharCount, TextFormatFlags dwFlags, ref RECT pRect, ref DTTOPTS pOptions);