WM_NCPAINT
internal class NonClientRegionAPI
{
[DllImport( "DwmApi.dll" )]
public static extern void DwmIsCompositionEnabled( ref bool pfEnabled );
[StructLayout( LayoutKind.Sequential )]
public struct WTA_OPTIONS
{
public WTNCA dwFlags;
public WTNCA dwMask;
}
[Flags]
public enum WTNCA : uint
{
NODRAWCAPTION = 1,
NODRAWICON = 2,
NOSYSMENU = 4,
NOMIRRORHELP = 8,
VALIDBITS = NODRAWCAPTION | NODRAWICON | NOSYSMENU | NOMIRRORHELP
}
public enum WINDOWTHEMEATTRIBUTETYPE : uint
{
/// <summary>Non-client area window attributes will be set.</summary>
WTA_NONCLIENT = 1,
}
[DllImport( "uxtheme.dll" )]
public static extern int SetWindowThemeAttribute(
IntPtr hWnd,
WINDOWTHEMEATTRIBUTETYPE wtype,
ref WTA_OPTIONS attributes,
uint size );
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// Set your options. We want no icon and no caption.
SetWindowThemeAttributes( NonClientRegionAPI.WTNCA.NODRAWCAPTION | NonClientRegionAPI.WTNCA.NODRAWICON );
}
private void SetWindowThemeAttributes( NonClientRegionAPI.WTNCA attributes )
{
// This tests that the OS will support what we want to do. Will be false on Windows XP and earlier,
// as well as on Vista and 7 with Aero Glass disabled.
bool hasComposition = false;
NonClientRegionAPI.DwmIsCompositionEnabled( ref hasComposition );
if( !hasComposition )
return;
NonClientRegionAPI.WTA_OPTIONS options = new NonClientRegionAPI.WTA_OPTIONS();
options.dwFlags = attributes;
options.dwMask = NonClientRegionAPI.WTNCA.VALIDBITS;
// The SetWindowThemeAttribute API call takes care of everything
NonClientRegionAPI.SetWindowThemeAttribute(
this.Handle,
NonClientRegionAPI.WINDOWTHEMEATTRIBUTETYPE.WTA_NONCLIENT,
ref options,
(uint)Marshal.SizeOf( typeof( NonClientRegionAPI.WTA_OPTIONS ) ) );
}
}
http://img708.imageshack.us/img708/1972/noiconnocaptionform.png