using System.Runtime.InteropServices; [DllImport("kernel32")] static extern int GetVersionExA(ref OSVERSIONINFO 系统信息); [DllImport("user32")] static extern long GetWindowLongA(int hWnd, int nIndex); [DllImport("user32")] static extern int SetWindowLongA(int hWnd, int nIndex, long dwNewLong); [DllImport("user32")] static extern int SetLayeredWindowAttributes(int hWnd, int cr, int alp, int index); [DllImport("dwmapi")] static extern int DwmIsCompositionEnabled(ref int pfEnabled); [DllImport("dwmapi")] static extern int DwmEnableComposition(int uCompositionAction); [DllImport("dwmapi")] static extern int DwmExtendFrameIntoClientArea(int hWnd, ref _MARGINS pMarInset); [DllImport("dwmapi")] static extern int DwmEnableBlurBehindWindow(int hWnd, ref _DWM_BLURBEHIND pBlurBehind); int hWnd = new int();//定义程序集变量 public struct OSVERSIONINFO { public int dwOSVersionInfoSize; public int dwMajorVersion; public int dwMinorVersion; public int dwBuildNumber; public int dwPlatformId; } public struct _MARGINS { public int cxLeftWidth; public int cxRightWidth; public int cyTopHeight; public int cyBottomHeight; }
[DllImport("kernel32")]
static extern int GetVersionExA(ref OSVERSIONINFO 系统信息);
[DllImport("user32")]
static extern long GetWindowLongA(int hWnd, int nIndex);
[DllImport("user32")]
static extern int SetWindowLongA(int hWnd, int nIndex, long dwNewLong);
[DllImport("user32")]
static extern int SetLayeredWindowAttributes(int hWnd, int cr, int alp, int index);
[DllImport("dwmapi")]
static extern int DwmIsCompositionEnabled(ref int pfEnabled);
[DllImport("dwmapi")]
static extern int DwmEnableComposition(int uCompositionAction);
[DllImport("dwmapi")]
static extern int DwmExtendFrameIntoClientArea(int hWnd, ref _MARGINS pMarInset);
[DllImport("dwmapi")]
static extern int DwmEnableBlurBehindWindow(int hWnd, ref _DWM_BLURBEHIND pBlurBehind); int hWnd = new int();//定义程序集变量 public struct OSVERSIONINFO
{
public int dwOSVersionInfoSize;
public int dwMajorVersion;
public int dwMinorVersion;
public int dwBuildNumber;
public int dwPlatformId;
}
public struct _MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
{
hWnd = Handle.ToInt32(); //判断系统版本,6和6以上版本可以使用
OSVERSIONINFO 版本信息 = new OSVERSIONINFO();
版本信息.dwOSVersionInfoSize = 148;
GetVersionExA(ref 版本信息);
if (版本信息.dwMajorVersion < 6)
{
MessageBox.Show("当前系统版本无法使用Areo!");
DestroyHandle();
} long nIndex = GetWindowLongA(hWnd, -20);
nIndex = nIndex | 524288;
SetWindowLongA(hWnd, -20, nIndex);
SetLayeredWindowAttributes(hWnd, 16711680, 255, 1);
}
{
int pfEnabled = new int();
DwmIsCompositionEnabled(ref pfEnabled);
if (pfEnabled == 1)
{
MessageBox.Show("该系统开启了Areo效果");
}
else
{
MessageBox.Show("该系统没有开启Areo效果");
}
} private void button2_Click(object sender, EventArgs e)
{
DwmEnableComposition(0);
MessageBox.Show("已经在当前进程关闭Aero 退出进程后界面会自动恢复");
} private void button3_Click(object sender, EventArgs e)
{
DwmEnableComposition(1);
MessageBox.Show("已经在当前进程开启Aero 退出进程后界面会自动恢复");
} private void button4_Click(object sender, EventArgs e)
{
this.BackColor = ColorTranslator.FromWin32(16711680);
checkedListBox1.BackColor = ColorTranslator.FromWin32(16711680);
progressBar1.BackColor = ColorTranslator.FromWin32(16711680);
textBox1.BackColor = ColorTranslator.FromWin32(16711680);
tabPage1.BackColor = ColorTranslator.FromWin32(16711680);
tabPage2.BackColor = ColorTranslator.FromWin32(16711680);
tabPage1.ForeColor = ColorTranslator.FromWin32(16711680);
tabPage2.ForeColor = ColorTranslator.FromWin32(16711680);
_MARGINS sRT = new _MARGINS();
sRT.cxLeftWidth = -1;
DwmExtendFrameIntoClientArea(hWnd, ref sRT);
}
这句报异常
“AccessViolationException异常,尝试读取或写人受保护的内存。这通常指示其他内存已损坏。”
不过areo 我用SkinH_Net 解决 嘎嘎 自己写不好用哦..
不知道楼主这个 xp下实验过吗?