|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Contents
1. IntroductionIn this article, I will show you how to apply XP-styles to a 2. BackgroundVisual Styles are not fully supported in NET 1.1. There is a bug in the 3. Where to draw the borderNormally, in NET, all paintings are done in the
4. The implementation in C#4.1 Filter some Windows messages in the RichTextBoxWhen we customize the window frame, we must filter some messages and process them.
/// <summary>
/// Filter some message we need to draw the border.
/// </summary>
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case NativeMethods.WM_NCPAINT:
// the border painting is done here.
WmNcpaint(ref m);
break;
case NativeMethods.WM_NCCALCSIZE:
// the size of the client area is calcuated here.
WmNccalcsize(ref m);
break;
default:
base.WndProc (ref m);
break;
}
}
4.2 Find out if you should render with XP stylesTo find out if we should render an application with visual styles, is not an easy task. There are three things to consider.
After Googling around in the web, I found a method that does the job: IsVisualStylesEnabled Revisited. 4.3 Get the device context of the window frameTo draw in the window frame, we need some Win32-APIs to get the corresponding device context (DC).
Here are the declarations in C#: [DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("gdi32.dll")]
public static extern int ExcludeClipRect(IntPtr hdc,
int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
4.4 Draw the border using uxTheme.dllDrawing visual styles is provided through the uxTheme.dll. We only need a few functions to draw the border.
Here are the declarations in C#. [DllImport("uxtheme.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]
public static extern IntPtr
OpenThemeData(IntPtr hWnd, String classList);
[DllImport("uxtheme", ExactSpelling=true)]
public extern static Int32 GetThemeBackgroundContentRect(IntPtr hTheme,
IntPtr hdc, int iPartId, int iStateId,
ref RECT pBoundingRect, out RECT pContentRect);
[DllImport("uxtheme", ExactSpelling=true)]
public extern static Int32 DrawThemeBackground(IntPtr hTheme,
IntPtr hdc, int iPartId, int iStateId,
ref RECT pRect, IntPtr pClipRect);
[DllImport("uxtheme.dll", ExactSpelling=true)]
public extern static Int32 CloseThemeData(IntPtr hTheme);
5. Points of interestsThe .NET Framework 2.0 contains new classes for drawing visual styles. You can find them in the 6. History
|
||||||||||||||||||||||