I'm trying to get the glow style text shown in win vista/7 title bar in my VB applications to use for labels/textboxes.
Image of glowing text:
[IMG]http://img248.imageshack.us/img248/3972/capturegm.jpg[/IMG]
Anybody know how to do this in visual basic ( visual studio 2010)?
Well, it probably goes beyond your area of programming if you're using Visual Basic, or what it's capable of. But you'd probably have to manually render that effect. I don't think that there is a setting for that in VB for fonts / effects.
[code] public class AeroGlass
{
#region API
[DllImport("dwmapi.dll")]
public static extern void DwmIsCompositionEnabled(ref bool pfEnabled);
[DllImport("dwmapi.dll")]
public static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMargins);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll", ExactSpelling = true)]
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
public static extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
public static extern bool DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern bool BitBlt(IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, UInt32 dwRop);
[DllImport("UxTheme.dll", CharSet = CharSet.Unicode)]
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);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateDIBSection(IntPtr hdc, BITMAPINFO pbmi, UInt32 iUsage, int ppvBits, IntPtr hSection, UInt32 dwOffset);
#endregion
#region Constants
public const int DTT_COMPOSITED = 8192;
public const int DTT_GLOWSIZE = 2048;
public const int DTT_TEXTCOLOR = 1;
public const int SRCCOPY = 0x00CC0020;
public const int DT_CENTER = 0x1;
public const int DT_VCENTER = 0x4;
#endregion
#region Structures
[StructLayout(LayoutKind.Sequential)]
public struct DTTOPTS
{
public int dwSize;
public int dwFlags;
public int crText;
public int crBorder;
public int crShadow;
public int iTextShadowType;
public POINT ptShadowOffset;
public int iBorderSize;
public int iFontPropId;
public int iColorPropId;
public int iStateId;
public bool fApplyOverlay;
public int iGlowSize;
public int pfnDrawTextCallback;
public IntPtr lParam;
}
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
public class BITMAPINFO
{
public int biSize;
public int biWidth;
public int biHeight;
public short biPlanes;
public short biBitCount;
public int biCompression;
public int biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public int biClrUsed;
public int biClrImportant;
public byte bmiColors_rgbBlue;
public byte bmiColors_rgbGreen;
public byte bmiColors_rgbRed;
public byte bmiColors_rgbReserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public int left;
public int right;
public int top;
public int bottom;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
public RECT(int iLeft, int iTop, int iRight, int iBottom)
{
Left = iLeft;
Top = iTop;
Right = iRight;
Bottom = iBottom;
}
public RECT(Rectangle r)
{
Left = r.X;
Top = r.Y;
Right = r.Right;
Bottom = r.Bottom;
}
}
#endregion
#region public Methods
public static bool IsCompositionEnabled
{
get
{
if (Environment.OSVersion.Version.Major < 6) return false;
bool compositionEnabled = false;
DwmIsCompositionEnabled(ref compositionEnabled);
return compositionEnabled;
}
}
public static void ExtendGlassIntoClientArea(Form f, int leftMargin, int topMargin, int rightMargin, int bottomMargin)
{
MARGINS m = new MARGINS();
m.left = leftMargin;
m.right = rightMargin;
m.top = topMargin;
m.bottom = bottomMargin;
DwmExtendFrameIntoClientArea(f.Handle, ref m);
}
public void PaintGlass(IntPtr pHdc, IntPtr mHdc, Rectangle r)
{
Bitmap buffer = new Bitmap(r.Width, r.Height);
IntPtr Ptr = buffer.GetHbitmap(Color.Black);
IntPtr Ptr2 = SelectObject(mHdc, Ptr);
BitBlt(pHdc, r.Left, r.Top, r.Width, r.Height, mHdc, 0, 0, Convert.ToUInt32(SRCCOPY));
DeleteObject(Ptr2);
}
public static void DrawGlowingText(Graphics g, string text, Font font, Rectangle bounds, Color color)
{
IntPtr primaryHdc = g.GetHdc();
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;
IntPtr dib = CreateDIBSection(primaryHdc, info, Convert.ToUInt32(0), 0, IntPtr.Zero, Convert.ToUInt32(0));
SelectObject(memoryHdc, dib);
IntPtr fontHandle = font.ToHfont();
SelectObject(memoryHdc, fontHandle);
DTTOPTS dttOpts = new DTTOPTS();
dttOpts.dwSize = Marshal.SizeOf(typeof(DTTOPTS));
dttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE | DTT_TEXTCOLOR;
dttOpts.crText = ColorTranslator.ToWin32(color);
dttOpts.iGlowSize = 10;
RECT textBounds = new RECT(0, 0, bounds.Right - bounds.Left, bounds.Bottom - bounds.Top);
IntPtr ptr = new IntPtr(65536);
DrawThemeTextEx(ptr, memoryHdc, 0, 0, text, -1, 2084 | DT_CENTER, ref textBounds, ref dttOpts);
BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, Convert.ToUInt32(SRCCOPY));
DeleteObject(dib);
DeleteObject(fontHandle);
DeleteDC(memoryHdc);
g.ReleaseHdc(primaryHdc);
}
#endregion
}
}[/code]
i've used this at one point. it's c# but you should get the idea. mainly DrawGlowingText
and it's probably all wrong.
Personally, i'd just create a .gif of what I want, and draw it as a graphic on the screen. You could do it through code, but it'd be a lot more effort for what you want to do.
Sorry, you need to Log In to post a reply to this thread.