使用Unity3d做异形窗口
项目马上上线,因为之前的登录器是使用VS2010的MFC做的,在很多电脑上会提示缺失mfcXXXX.dll,中间找寻这种解决方案,最后确定将vcredist2010_x86和我的程序打包到安装包里面,每次安装的时候默认先安装vcredist2010_x86。
由此,经常被杀毒软件阻止,而且还有x64 or x86的区别。
同时,甲方想要一个精灵,类似于QQ宠物,于是PL决定使用精灵模型+异形窗口做一个桌面宠物。于是,异形窗口成了此物的基础。
首先,我们需要了解的是,异形窗口是什么。简单来说,即将窗口形状变成由一张不规则(一般由透明色决定)图片所决定的形状。
然后,需要知道的是窗口的形状是由什么决定。在MSDN上我发现,普通的窗口形状由一个简单的Rectangular Region决定。经查询之后,要实现异形窗口主要要靠这几个函数:
a. 创建一个矩形区域
//The CreateRectRgn function creates a rectangular region.
HRGN CreateRectRgn(
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
);
b. 结合n个矩形区域
//The CombineRgn function combines two regions and stores the result in a third region.
//The two regions are combined according to the specified mode. int CombineRgn(
HRGN hrgnDest, // handle to destination region
HRGN hrgnSrc1, // handle to source region
HRGN hrgnSrc2, // handle to source region
int fnCombineMode // region combining mode
);
c. 将窗口显示出来
//The SetWindowRgn function sets the window region of a window.
//The window region determines the area within the window where the system permits drawing.
//The system does not display any portion of a window that lies outside of the window region int SetWindowRgn(
HWND hWnd, // handle to window
HRGN hRgn, // handle to region
BOOL bRedraw // window redraw option
);
d. 去掉窗口标题栏(主要窗口截图只能截到窗口边框内)
//This function changes an attribute of the specified window.
//SetWindowLong also sets a 32-bit (LONG) value at the specified offset into the extra window memory of a window.
LONG SetWindowLong(
HWND hWnd,
int nIndex,
LONG dwNewLong
);
最后,在unity里面调用user32.dll 和 Gdi32.dll 两个动态链接库,结合unity界面截图,得到最后的处理结果。贴上部分处理代码:
/// <summary>
/// use the screen shot image to cut the window.
/// </summary>
private void updateWindow() {
System.IntPtr hRgn = WinAPI.CreateRectRgn(, , , ); Debug.Log(" width: " + winTex2d.width + " height: " + winTex2d.height); for (int h = ; h < winTex2d.height; ++h) {//int h = tex2d.height - 1; h > tex2d.height/2; --h
//Debug.Log(tex2d.GetPixel(h, h));
int w = ;
do {
while (w < winTex2d.width && (winTex2d.GetPixel(w, winTex2d.height - h) == Color.clear
|| winTex2d.GetPixel(w, h) == Color.black
)) {
++w;
//Debug.Log(tex2d.GetPixel(w, h));
}
int iLeftX = w;
while (w < winTex2d.width && (winTex2d.GetPixel(w, winTex2d.height - h) != Color.clear
//|| tex2d.GetPixel(w, h) != Color.black
)) {
++w;
//Debug.Log(tex2d.GetPixel(w, h));
}
//Debug.Log("ileftX: " + iLeftX + "w: " + w + h); WinAPI.CombineRgn(hRgn, hRgn, WinAPI.CreateRectRgn(iLeftX, h, w, h + ), );
}//end do{}
while (w < winTex2d.width);
}//end for(h); Debug.Log("setWindowRgn: " + WinAPI.SetWindowRgn(WinAPI.GetActiveWindow(), hRgn, true));
}//end updateWindow();
PS:这种处理方式当图形透明区域特别多的时候,会出现整个处理过程有些卡顿,后期可能要加入线程进行处理。
感谢您的阅读,如果您有好的建议,望不吝赐教!
使用Unity3d做异形窗口的更多相关文章
- 一个最简单的Delphi2010的PNG异形窗口方法
		
同事演示了一个.NET的的PNG异形窗口.挺漂亮.于是也想用Delphi显摆一个. 关于Delphi用PNG做异形窗口的资料有不少.都是用GDIPlus或者TPNGImage组件加载PNG图像做的.但 ...
 - [Unity3D]做个小Demo学习Input.touches
		
[Unity3D]做个小Demo学习Input.touches 学不如做,下面用一个简单的Demo展示的Input.touches各项字段,有图有真相. 本项目已发布到Github,地址在(https ...
 - WPF Window异形窗口演示
		
我们先通过简单的效果展示,切换展示不同图片: 我们先定义图片资源文件,我们可以在window资源中定义,下面的在app.xaml文件来定义: <Application x:Class=" ...
 - QT中异形窗口的绘制(winEvent处理WM_NCHITTEST消息)
		
这里讨论的只是Windows平台上的实现. 在QT中绘制异形窗口,只要设定 windowFlag 为 CustomizeWindowHint,再结合setMask()就可以做出各种奇形怪状的窗口.相对 ...
 - Win32创建异形窗口
		
大家都见过在windows下各种气泡窗口.输入法窗口以及其他一些窗口,这些窗口看起来不像传统的windows窗那样,上面是标题栏,下面是窗口的客户区.这些窗口形状各异,可以是一个多边形,一幅图,甚至是 ...
 - [用UpdateLayeredWindow实现任意异形窗口]
		
前面提到,我们可以用SetWindowRgn或SetLayeredWindowAttributes实现不规则以及半透明的效果 对于SetWindowRgn,它通过一个Rgn来设置区域,这个Rgn一般可 ...
 - 用Unity3d做游戏(一)
		
准备工作: vs2013,直接从官网下载或者这里 http://pan.baidu.com/s/1bFxC54 unity3d,从官网下载,版本4或者5 https://unity3d.com/c ...
 - c# UpdateLayeredWindow异形窗口
		
#region UpdateLayeredWindow #region 重写窗体的 CreateParams 属性 protected override CreateParams CreatePara ...
 - 窗口界面编程之一:VB实现简单异形窗口
		
一.运行效果图(在Win8里的运行效果,在XP里运行就不能体现出来,因为我使用的XP的界面效果) 二.编译环境:Visual Basic 6.0 (SP6) 三.实现原理:通过区域合并 四.使用API ...
 
随机推荐
- Spring-Context之八:一些依赖注入的小技巧
			
Spring框架在依赖注入方面是非常灵活和强大的,多了解点一些注入的方式.方法,绝对能优化配置. idref idref属性可以传入一个bean的名称,虽然它是指向一个bean的引用,但是得到的是该b ...
 - linux expect详解(ssh自动登录)
			
shell脚本实现ssh自动登录远程服务器示例: #!/usr/bin/expect spawn ssh root@192.168.22.194 expect "*password:&quo ...
 - HTML5 WebStorage
			
WebStorage是HTML5中本地存储的解决方案之一,在HTML5的WebStorage概念引入之前除去IE User Data.Flash Cookie.Google Gears等看名字就不靠谱 ...
 - asp.net web api CORS
			
using System; using System.Web.Http.Filters; public class AllowCrossSiteJsonAttribute : ActionFilter ...
 - sql的OUTER APPLY
			
今天写一个查询sql,其中涉及到一个银行卡绑定表(表名:BankBind),我要将这个表的开户行字段的值进行分割出省份.支行, 这个开户行字段存储的值如“广东省广东省分行江门市分行恩平市支行”.“招商 ...
 - wep.py输出hello world
			
webpy是python的一个简单的web开发的框架.可以通过简单的几行代码启动一个web服务(虽然只是输出helloworld). 准备工作 准备工具如下: 下载python[python开发环境] ...
 - Atitit 数据存储的数据表连接attilax总结
			
Atitit 数据存储的数据表连接attilax总结 1.1. 三种物理连接运算符:嵌套循环连接.合并连接以及哈希连接1 1.2. a.嵌套循环连接(nested loops join)1 1.3. ...
 - Android笔记——Android框架
			
本篇将站在顶级的高度--架构,来看android.我开篇就说了,这个系列适合0基础的人且我也是从0开始按照这个步骤来 学的,谈架构是不是有点螳臂挡车,自不量力呢?我觉得其实不然,如果一开始就对整个an ...
 - DOM_05之DOM、BOM常用对象
			
1.HTML DOM常用对象之Table:①创建:createTHead():createTBody():createTFoot():②删除:deleteTHead():deleteTFoot():③ ...
 - nginx上部署python web
			
nginx上部署python web http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html