namespace suoding
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
const int CS_DropSHADOW = 0*20000;
const int GCL_STYLE = (-26);
WinAPI.SetClassLong(this.Handle, GCL_STYLE, WinAPI.GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Parent = WinAPI.GetWindow();
return cp;
}
} private void SetWindowShadow(byte bAlpha)
{
WinAPI.SetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE,
WinAPI.GetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE) | (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);
WinAPI.SetLayeredWindowAttributes(this.Handle, 0, bAlpha, WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);
}
}
}下面是类
namespace suoding
{
public class WinAPI
{
[DllImport("user32.dll")]
public extern static IntPtr GetWindow(); [DllImport("user32.dll")]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public static uint LWA_COLORKEY = 0 * 00000001;
public static uint LWA_ALPHA = 0 * 00000002; #region 阴影效果变量
//声明Win32 API
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll")]
public extern static uint GetWindowLong(IntPtr hwnd, int nIndex);
#endregion public enum WindowStyle : int
{
GWL_EXSTYLE = -20
} public enum ExWindowStyle : uint
{
WS_EX_LAYERED = 0 * 00080000
}
}
}报一个不再能力之内的错,求帮助,我是win7,vs2010.先谢了。
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
const int CS_DropSHADOW = 0*20000;
const int GCL_STYLE = (-26);
WinAPI.SetClassLong(this.Handle, GCL_STYLE, WinAPI.GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Parent = WinAPI.GetWindow();
return cp;
}
} private void SetWindowShadow(byte bAlpha)
{
WinAPI.SetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE,
WinAPI.GetWindowLong(this.Handle, (int)WinAPI.WindowStyle.GWL_EXSTYLE) | (uint)WinAPI.ExWindowStyle.WS_EX_LAYERED);
WinAPI.SetLayeredWindowAttributes(this.Handle, 0, bAlpha, WinAPI.LWA_COLORKEY | WinAPI.LWA_ALPHA);
}
}
}下面是类
namespace suoding
{
public class WinAPI
{
[DllImport("user32.dll")]
public extern static IntPtr GetWindow(); [DllImport("user32.dll")]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public static uint LWA_COLORKEY = 0 * 00000001;
public static uint LWA_ALPHA = 0 * 00000002; #region 阴影效果变量
//声明Win32 API
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassLong(IntPtr hwnd, int nIndex);
[DllImport("user32.dll")]
public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
[DllImport("user32.dll")]
public extern static uint GetWindowLong(IntPtr hwnd, int nIndex);
#endregion public enum WindowStyle : int
{
GWL_EXSTYLE = -20
} public enum ExWindowStyle : uint
{
WS_EX_LAYERED = 0 * 00080000
}
}
}报一个不再能力之内的错,求帮助,我是win7,vs2010.先谢了。
对 PInvoke 函数“suoding!suoding.WinAPI::GetWindow”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
HWND WINAPI GetWindow(
__in HWND hWnd,
__in UINT uCmd
);
public static extern IntPtr GetWindow(IntPtr hwnd, int wFlag);