Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums

Go Back   Vista Forums > Vista technology newsgroups > Aero

DrawThemeTextEx in .NET

Reply
 
Thread Tools Display Modes
Old 12-10-2006   #1
Jan Kucera
Guest
 
Posts: n/a

DrawThemeTextEx in .NET

Hi - I just wondered, if there is anything simpler than this?
Thanks, Jan


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);
}
}
}

  Reply With Quote

Old 01-17-2007   #2
Jan Kucera
Guest
 
Posts: n/a

Re: DrawThemeTextEx in .NET

There is not more managed way to draw window caption? Without bitblts?
Jan


"Jan Kucera" <kucera@lupacovka.cz> wrote in message
news:F6579CA6-50D0-436D-95F4-7769168D1CFF@microsoft.com...
> Hi - I just wondered, if there is anything simpler than this?
> Thanks, Jan
>
>
> 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);
> }
> }
> }
>


  Reply With Quote
 
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET 3.0 problems =?Utf-8?B?TUNTRQ==?= Vista installation & setup 1 10-03-2006 07:17 PM
.NET problem and installing programs Beck Vista General 0 08-30-2006 01:32 PM
Installing Visual Studio .NET 2003 on Vista Build 5456 =?Utf-8?B?SmFtZXMgU2ltcHNvbg==?= Vista General 1 07-17-2006 11:00 AM
.NET Framework catch-22 Richard Helms Vista General 1 06-12-2006 05:41 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Vistax64.com 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48