刚用到这个功能,网上扯淡的东西太多了,都是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. win8提升winform软件的权限

    在win8系统中,微软提高了系统盘文件的权限,提高了其他系统操作的权限,因此一些桌面应用程序在运行时会报一些权限错误,比如C盘文件操作权限,或注册表操作无权限等. 我之前开发过一款用笔记本一键架设无线 ...

  2. Java:国际化

    Java的国际化: 资源文件的命名可以有如下三种形式:baseName _ language _country.properties baseName _language.properties bas ...

  3. C语言fmod()函数:对浮点数取模(求余)

    头文件:#include <math.h> fmod() 用来对浮点数进行取模(求余),其原型为:    double fmod (double x); 设返回值为 ret,那么 x = ...

  4. python 实现树结构的打印

    class TreeNode: def __init__(self,value): self.children = [] self.value = value def add_child(self,* ...

  5. thinkPHP环境搭建小记

    php一直以来都被人诟病,说什么设计得很糟糕,有种你别用啊,不然就别bb了.最近,森哥在去年暑假学习了php基础和mvc模式的基础上准备用尝试一下国产ThinkPHP框架. 1.搭建LAMP环境 我实 ...

  6. 如何创建vss2005的数据库

    配置如下 VSS手工创建数据库的步骤(设数据库根目录为D:\VSS): 1.在根目录中创建名为srcsafe.ini(全局配置文件)的文件,文件内容如下: Data_Path = data Temp_ ...

  7. Junit3断言

    在Robotium自动化测试的过程中,发现没有断言的脚本是没有意义的,现整理Junit3和Junit4的断言,供日后查阅. http://junit.org/ Junit3断言API: http:// ...

  8. 这些年正Android - 大学

     还记得,第一次看见小周是在大一的操场上. 她正向教学楼站着,一身白配粉的休闲上衣搭配湖蓝色的牛仔裤,穿着一双很平凡的凉鞋,手里拿着当年的Nokia 3110c,皙清的手指,素颜的站着不言不笑.现在回 ...

  9. Iphone连接win10电脑正常, itunes无法识别解决

    1.之前试过重装itunes, apple的两个服务也都已经启动. 2.但是设备管理器不显示移动设备或者usb的apple mobile device driver 3.解决:打开C:\Program ...

  10. bootstrap 无限极菜单

        <ul class='wraplist' >           <li class="open">                <a hr ...