刚用到这个功能,网上扯淡的东西太多了,都是2边阴影,还什么窗口叠加、ps作图啥的,什么玩意。还是老外实在,google找的,无边框窗体,四边透明阴影。

public partial class Form1 : Form
{
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
); [DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset); [DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); [DllImport("dwmapi.dll")]
public static extern int DwmIsCompositionEnabled(ref int pfEnabled); private bool m_aeroEnabled; // variables for box shadow
private const int CS_DROPSHADOW = 0x00020000;
private const int WM_NCPAINT = 0x0085;
private const int WM_ACTIVATEAPP = 0x001C; public struct MARGINS // struct for box shadow
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
} private const int WM_NCHITTEST = 0x84; // variables for dragging the form
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2; protected override CreateParams CreateParams
{
get
{
m_aeroEnabled = CheckAeroEnabled(); CreateParams cp = base.CreateParams;
if (!m_aeroEnabled)
cp.ClassStyle |= CS_DROPSHADOW; return cp;
}
} private bool CheckAeroEnabled()
{
if (Environment.OSVersion.Version.Major >= )
{
int enabled = ;
DwmIsCompositionEnabled(ref enabled);
return (enabled == ) ? true : false;
}
return false;
} protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCPAINT: // box shadow
if (m_aeroEnabled)
{
var v = ;
DwmSetWindowAttribute(this.Handle, , ref v, );
MARGINS margins = new MARGINS()
{
bottomHeight = ,
leftWidth = ,
rightWidth = ,
topHeight =
};
DwmExtendFrameIntoClientArea(this.Handle, ref margins); }
break;
default:
break;
}
base.WndProc(ref m); if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT) // drag the form
m.Result = (IntPtr)HTCAPTION; } public Form1()
{
m_aeroEnabled = false; this.FormBorderStyle = FormBorderStyle.None; InitializeComponent();
}
}

初学c# -- 学习笔记(五) winfrom无边框四周阴影的更多相关文章

  1. Learning ROS for Robotics Programming Second Edition学习笔记(五) indigo computer vision

    中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...

  2. muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor

    目录 muduo网络库学习笔记(五) 链接器Connector与监听器Acceptor Connector 系统函数connect 处理非阻塞connect的步骤: Connetor时序图 Accep ...

  3. 初学c# -- 学习笔记(一)

    初学c# -- 学习笔记(一) 学习C#了,参考许多资料,一步步学习.这一段学习ajax的工作原理,参照其他例子写了web版的群聊小程序,全部文件代码也就不到300行,很简单.使用时先输入用户名,点确 ...

  4. C#可扩展编程之MEF学习笔记(五):MEF高级进阶

    好久没有写博客了,今天抽空继续写MEF系列的文章.有园友提出这种系列的文章要做个目录,看起来方便,所以就抽空做了一个,放到每篇文章的最后. 前面四篇讲了MEF的基础知识,学完了前四篇,MEF中比较常用 ...

  5. (转)Qt Model/View 学习笔记 (五)——View 类

    Qt Model/View 学习笔记 (五) View 类 概念 在model/view架构中,view从model中获得数据项然后显示给用户.数据显示的方式不必与model提供的表示方式相同,可以与 ...

  6. java之jvm学习笔记五(实践写自己的类装载器)

    java之jvm学习笔记五(实践写自己的类装载器) 课程源码:http://download.csdn.net/detail/yfqnihao/4866501 前面第三和第四节我们一直在强调一句话,类 ...

  7. Typescript 学习笔记五:类

    中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...

  8. ES6学习笔记<五> Module的操作——import、export、as

    import export 这两个家伙对应的就是es6自己的 module功能. 我们之前写的Javascript一直都没有模块化的体系,无法将一个庞大的js工程拆分成一个个功能相对独立但相互依赖的小 ...

  9. python3.4学习笔记(五) IDLE显示行号问题,插件安装和其他开发工具介绍

    python3.4学习笔记(五) IDLE显示行号问题,插件安装和其他开发工具介绍 IDLE默认不能显示行号,使用ALT+G 跳到对应行号,在右下角有显示光标所在行.列.pycharm免费社区版.Su ...

随机推荐

  1. js判断浏览器

    function myBrowser(){ var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 ; if (isOpera) { ret ...

  2. Unity3D 事件

    unity3d事件函数整理,事件,回调函数,消息处理 Unity3D中所有控制脚本的基类MonoBehaviour有一些虚函数用于绘制中事件的回调,也可以直接理解为事件函数,例如大家都很清楚的Star ...

  3. 【HOW】如何允许编辑用户配置文件属性

    在自定义用户配置文件属性后会发现,通过属性本身的配置页面,只能允许用户修改自己的属性,而管理员无法修改其他用户的属性.若要允许管理员在用户信息页面修改用户配置文件属性,可通过如下操作实现: 1. 进入 ...

  4. spring 学习之 bean 的注入方式 property和constructor-arg的使用方式

    spring 学习之 bean 的注入方式 property和constructor-arg的使用方式. bean的注入方式: property 注入是: 通过setxx方法注入. construct ...

  5. android ImageView 中的ScaleType

    center :居中,不执行缩放 centerCrop:按原始比例缩放,裁剪中间部分 centerInside:按原始比例缩放,居中,不裁剪 fitCenter:居中缩放 fitStart:上对齐缩放 ...

  6. javascript的地基

    有了良好的基础,才能在其上创造有价值的东西. 回顾一下以往自己javascript应用的开发经历,似乎很少去思考和总结js的运行机制.现在我就来整理整理 1. 以<编译原理>的一段话开头: ...

  7. 详解rsync算法--如何减少同步文件时的网络传输量

    先看下图中的场景,客户端A和B,以及服务器server都保存了同一个文件,最初,A.B和server上的文件内容都是相同的(记为File.1).某一时刻,B修改了文件内容,上传到SERVER上(记为F ...

  8. adb server无法终止问题

    这两天通过python去连接Android手机时,一直提示:Adb connection Error:An existing connection was forcibly closed by the ...

  9. nginx相关的一些记录

    http redirect to https: if ($http_cf_visitor ~ '"scheme":"http"'){ rewrite ^/(.* ...

  10. Axure 资料搜集

    Axure官方核心训练(翻译) http://www.webppd.com/thread-9347-1-1.html 原文链接:http://www.axure.com/learn 下载链接:http ...