中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > Visual C++ > 图形用户界面
如何创建一个不规则形状的窗口
作者:ShowMan 时间:2001-10-12 10:15 出处:互联网 责编:chinaitpower
              摘要:如何创建一个不规则形状的窗口

可以使用新的SDK函数SetWindowRgn。该函数将绘画和鼠标消息限定在窗口的一个指定的区域,实际上使窗口成为指定的不规则形状。

使用AppWizard创建一个基于对话框的应用程序并使用资源编辑器从主对话资源中删除有的缺省控件、标题以及边界。

给对话类增加一个CRgn数据成员,以后要使用该数据成员建立窗口区域。
Class CRoundDlg : public CDialog
{ …
private :
Crgn m_rgn : // window region
…}
修改OnInitDialog函数建立一个椭圆区域并调用SetWindowRgn将该区域分配给窗口:
BOOL CRoundDlg : : OnInitDialog ( )
{

CDialog : : OnInitDialog ( )

//Get size of dialog .

CRect rcDialog ;

GetClientRect (rcDialog )

// Create region and assign to window .

m_rgn . CreateEllipticRgn (0 , 0 , rcDialog.Width( ),

rcDialog.Height ( ) )

SetWindowRgn (GetSafeHwnd ( ) , (HRGN) m_ rgn ,TRUE );

return TRUE
}
通过建立区域和调用SetWindowRgn,已经建立一个不规则形状的窗口,下面的例子程序是修改OnPaint函数使窗口形状看起来象一个球形体。
voik CRoundDlg : : OnPaint ( )
{
CPaintDC de (this) // device context for painting.
//draw ellipse with out any border
dc. SelecStockObject (NULL_PEN)
//get the RGB colour components of the sphere color
COLORREF color= RGB( 0 , 0 , 255)
BYTE byRed =GetRValue (color)
BYTE byGreen = GetGValue (color)
BYTE byBlue = GetBValue (color)
// get the size of the view window Crect
rect GetClientRect (rect)
// get minimun number of units
int nUnits =min (rect.right , rect.bottom )
//calculate he horiaontal and vertical step size
float fltStepHorz = (float) rect.right /nUnits
float fltStepVert = (float) rect.bottom /nUnits
int nEllipse = nUnits/3 // calculate how many todraw int nIndex
// current ellipse that is being draw
CBrush brush
// bursh used for ellipse fill color
CBrush *pBrushOld // previous brush that was selected into dc
//draw ellipse , gradually moving towards upper-rightcorner
for (nIndex = 0 nIndes < + nEllipse nIndes++)
{ //creat solid brush brush .
CreatSolidBrush (RGB ( ( (nIndex*byRed ) /nEllipse ).

( ( nIndex * byGreen ) /nEllipse ), ( (nIndex*byBlue)/nEllipse ) ) )
//select brush into dc
pBrushOld= dc .SelectObject (&brhsh)
//draw ellipse
dc .Ellipse ( (int) fltStepHorz * 2, (int)fltStepVert * nIndex ,
rect. right -( (int)fltStepHorz * nIndex )+ 1, rect . bottom -( (int)
fltStepVert * (nIndex *2) ) +1)
//delete the brush
brush.DelecteObject ( )
} }
最后,处理WM_NCHITTEST消息,使当击打窗口的任何位置时能移动窗口。
UINT CRoundDlg : : OnNchitTest (Cpoint point )
{
//Let user move window by clickign anywhere on thewindow .
UINT nHitTest = CDialog : : OnNcHitTest (point)
rerurn (nHitTest = = HTCLIENT)? HTCAPTION: nHitTest
}

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有