public class NativeMethods
{
/// <summary>
/// 带有外边框和标题的windows的样式
/// </summary>
public const long WS_CAPTION = 0X00C0000L;
// public const long WS_BORDER = 0X0080000L;
/// <summary>
/// window 扩展样式 分层显示
/// </summary>
public const long WS_EX_LAYERED = 0x00080000L;
/// <summary>
/// 带有alpha的样式
/// </summary>
public const long LWA_ALPHA = 0x00000002L;
/// <summary>
/// 颜色设置
/// </summary>
public const long LWA_COLORKEY = 0x00000001L;
/// <summary>
/// window的基本样式
/// </summary>
public const int GWL_STYLE = -16;
/// <summary>
/// window的扩展样式
/// </summary>
public const int GWL_EXSTYLE = -20;
/// <summary>
/// 设置窗体的样式
/// </summary>
/// <param name="handle">操作窗体的句柄</param>
/// <param name="oldStyle">进行设置窗体的样式类型.</param>
/// <param name="newStyle">新样式</param>
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern void SetWindowLong(IntPtr handle, int oldStyle, long newStyle);
/// <summary>
/// 获取窗体指定的样式.
/// </summary>
/// <param name="handle">操作窗体的句柄</param>
/// <param name="style">要进行返回的样式</param>
/// <returns>当前window的样式</returns>
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern long GetWindowLong(IntPtr handle, int style);
/// <summary>
/// 设置窗体的工作区域.
/// </summary>
/// <param name="handle">操作窗体的句柄.</param>
/// <param name="handleRegion">操作窗体区域的句柄.</param>
/// <param name="regraw">if set to <c>true</c> [regraw].</param>
/// <returns>返回值</returns>
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern int SetWindowRgn(IntPtr handle, IntPtr handleRegion, bool regraw);
/// <summary>
/// 创建带有圆角的区域.
/// </summary>
/// <param name="x1">左上角坐标的X值.</param>
/// <param name="y1">左上角坐标的Y值.</param>
/// <param name="x2">右下角坐标的X值.</param>
/// <param name="y2">右下角坐标的Y值.</param>
/// <param name="width">圆角椭圆的 width.</param>
/// <param name="height">圆角椭圆的 height.</param>
/// <returns>hRgn的句柄</returns>
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int width, int height);
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
/// <summary>
/// 该CombineRgn函数和存储结合了两个地区在第三地区的结果。结合这两个地区是根据指定的模式。
/// </summary>
/// <param name="hDestRgn1">处理到一个新的区域与其他区域相结合的两个定义尺寸。 (此区域之前,必须存在CombineRgn被调用。)</param>
/// <param name="hSrcRgn1">句柄两个区域首先要结合起来。</param>
/// <param name="hDestRgn2">句柄两个区域的第二个结合起来。</param>
/// <param name="hSrcRgn2">指定的模式表明这两个地区如何将被合并。这个参数可以是以下值之一。</param>
/// RGN_AND hDestRgn被设置为两个源区域的交集
//RGN_COPY hDestRgn被设置为hSrcRgn1的拷贝
//RGN_DIFF hDestRgn被设置为hSrcRgn1中与hSrcRgn2不相交的部分
//RGN_OR hDestRgn被设置为两个区域的并集
//RGN_XOR hDestRgn被设置为除两个源区域OR之外的部分
/// <returns>句柄</returns>
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern IntPtr CombineRgn(IntPtr hDestRgn1, IntPtr hSrcRgn1, IntPtr hDestRgn2, int hSrcRgn2);
/// <summary>
/// Sets the layered window attributes.
/// </summary>
/// <param name="handle">要进行操作的窗口句柄</param>
/// <param name="colorKey">RGB的值</param>
/// <param name="alpha">Alpha的值,透明度</param>
/// <param name="flags">附带参数</param>
/// <returns>true or false</returns>
[System.Runtime.InteropServices.DllImport("User32.dll")]
public static extern bool SetLayeredWindowAttributes(IntPtr handle, ulong colorKey, byte alpha, long flags);
}
下面的问题就是如何进行操作了,首先在进行嵌入WinForm控件的WPF窗体中添加一个Load事件,在事件中添加如下代码:
1.1 API常量参考(Constants Reference)
http://www.papazhu.com/post/Constants_Reference.php?page=1&part=7