【3D技术宅公社】XR数字艺术论坛  XR技术讨论 XR互动电影 定格动画

 找回密码
 立即注册

QQ登录

只需一步,快速开始

调查问卷
论坛即将给大家带来全新的技术服务,面向三围图形学、游戏、动画的全新服务论坛升级为UTF8版本后,中文用户名和用户密码中有中文的都无法登陆,请发邮件到324007255(at)QQ.com联系手动修改密码

3D技术论坛将以计算机图形学为核心,面向教育 推出国内的三维教育引擎该项目在持续研发当中,感谢大家的关注。

查看: 2375|回复: 0

[转帖]C++Builder中不规则窗体的快速显示

[复制链接]
发表于 2005-9-28 11:42:23 | 显示全部楼层 |阅读模式
 很多的游戏和工具软件都使用异形窗口来出奇至胜。其实创建异形窗口从技术上来说难度不大,但是有没有效果主要还是在于创意是否出奇。下面简单的介绍如何使用SetWindowRgn制作异形窗口。
<></P>
<>  SetWindowRgn是新的SDK函数。该函数将绘画消息和鼠标消息都限定在窗口的一个指定的区域内,实际上使窗口成为指定的不规则形状。 </P>
<></P>
<>  首先使用AppWizard创建一个基于对话框的应用程序,并使用资源编辑器从资源中删除有的缺省控件、标题以及边界。 </P>
<></P>
<>  给对话类增加一个CRgn数据成员,以便使用该数据成员建立窗口区域。 </P>
<></P>
<>Class CTestDlg:public CDialog </P>
<>{ … </P>
<>private: </P>
<P>   CRgn m_rgn; // window region </P>
<P>…} </P>
<P></P>
<P>   修改对话框的OnInitDialog函数,建立一个椭圆区域并调用SetWindowRgn将该区域分配给窗口: </P>
<P></P>
<P>BOOL CTestDlg::OnInitDialog () </P>
<P>{ </P>
<P></P>
<P>CDialog::OnInitDialog () </P>
<P></P>
<P>//得到对话框的尺寸 </P>
<P></P>
<P>CRect rcDialog; </P>
<P>GetClientRect (rcDialog) </P>
<P></P>
<P>//创建一个椭圆形的区域,并使用SetWindowRgn重设对话框的形状。 </P>
<P></P>
<P>m_rgn.CreateEllipticRgn (0 , 0 , rcDialog.Width(), </P>
<P>rcDialog.Height ()); SetWindowRgn (GetSafeHwnd () , (HRGN) m_ rgn,TRUE ); </P>
<P></P>
<P>return TRUE; </P>
<P>} </P>
<P></P>
<P>  一个简单的异形窗口已经生成,如果编译运行工程,将出现一个椭圆形的窗口。下面的代码是在OnPaint消息中进行处理,使得对话框具有立体效果。 </P>
<P></P>
<P>void CTestDlg::OnPaint () </P>
<P>{ </P>
<P>   CPaintDC paintDC (this); </P>
<P>   // 得到设备 // 设置画椭圆时不画边界 </P>
<P>   paintDC. SelecStockObject (NULL_PEN); </P>
<P>   // 得到球体的颜色 </P>
<P>   COLORREF ballColor= RGB( 0 , 0 , 255); </P>
<P>  BYTE byRed =GetRValue (ballColor); </P>
<P>  BYTE byGreen = GetGValue (ballColor) ; </P>
<P>  BYTE byBlue = GetBValue (ballColor) ; </P>
<P>   // 得到球体的范围。 </P>
<P>   Rect rcDialog; </P>
<P>   GetClientRect (rcDialog) ; </P>
<P>   // 得出画球体的最小单位 </P>
<P>   int nUnits =min (rcDialog.right , rcDialog.bottom ) ; </P>
<P>   //计算水平方向和垂直方向的画线单位。 </P>
<P>   float fltStepHorz = (float) rcDialog.right /nUnits ; </P>
<P>   float fltStepVert = (float) rcDialog.bottom /nUnits ; </P>
<P>   int nEllipse = nUnits/3 ; </P>
<P>   // 开始画出多个椭圆,以达到视觉上的立体感。 </P>
<P>   CBrush brush ; </P>
<P>   // 使用ballColor的颜色填充画刷。 </P>
<P>   CBrush *pBrushOld; </P>
<P>   // 存储旧画刷 </P>
<P></P>
<P>  for (nIndex = 0 ;nIndes &lt; nEllipse ;nIndes++) </P>
<P>  { </P>
<P>     CreatSolidBrush (RGB ( ( (nIndex*byRed ) /nEllipse ); </P>
<P></P>
<P>    ( ( nIndex * byGreen ) /nEllipse ), ( (nIndex*byBlue)/nEllipse ) ) ) ; </P>
<P>     pBrushOld= paintDC .SelectObject (&amp;brhsh) ; </P>
<P>     paintDC .Ellipse ( (int) fltStepHorz * 2, (int)fltStepVert * nIndex , </P>
<P>     rect. right -( (int)fltStepHorz * nIndex )+ 1, rect . bottom -( (int) </P>
<P>     fltStepVert * (nIndex *2) ) +1) ; </P>
<P>     brush.DelecteObject ( ) ; </P>
<P>   } </P>
<P>} </P>
<P></P>
<P>  异形窗口不是只适用于对话框,同样的适用于单文档,多文档类型的应用。如果读者有兴趣,可以自己进行尝试。如有疑问可发Mail至学院信箱。 </P>
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|3D数字艺术论坛 ( 沪ICP备14023054号 )

GMT+8, 2025-6-25 17:57

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表