⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index027.htm

📁 一本不错的VC编程的参考书
💻 HTM
字号:
<html>
<style type="text/css"><!--
.p9 {  font-family: "宋体"; font-size: 9pt}a        {text-transform: none; text-decoration: none;}
a:hover {text-decoration: underline; color: #FF0000;}
--></style>
<body background="../di2001.jpg">
<h3 align="center"><font COLOR="#AOAO99"></font></h3>
<table width="100%" border="1" cellspacing="1">
<tr><td><p align="center"><font color="#FF0000">如何创建一个不规则形状的窗口</font></td></tr>
<tr><td><p>
</Br>
可以使用新的SDK函数SetWindowRgn。该函数将绘画和鼠标消息限定在窗口的一个指定的区域,实际上使窗口成为指定的不规则形状。 使用AppWizard创建一个基于对的应用程序并使用资源编辑器从主对话资源中删除所在的缺省控件、标题以及边界。<Br>
给对话类增加一个CRgn数据成员,以后要使用该数据成员建立窗口区域。<Br>
Class CRoundDlg : public CDialog<Br>
{<Br>
&nbsp;…<Br>
private :<Br>
&nbsp;Crgn m_rgn : // window region<Br>
&nbsp;…<Br>
}<Br>
修改OnInitDialog函数建立一个椭圆区域并调用SetWindowRgn将该区域分配给窗口:<Br>
BOOL CRoundDlg : : OnInitDialog ( )<Br>
{<Br>
&nbsp;CDialog : : OnInitDialog ( )<Br>
</Br>
&nbsp;//Get size of dialog .<Br>
&nbsp;CRect rcDialog<Br>
&nbsp;GetClientRect (rcDialog )<Br>
</Br>
&nbsp;// Create region and assign to window .<Br>
&nbsp;m_rgn . CreateEllipticRgn (0 , 0 , rcDialog.Width( ) , rcDialog.Height ( ) )<Br>
&nbsp;SetWindowRgn (GetSafeHwnd ( ) , (HRGN) m_ rgn ,TRUE )<Br>
</Br>
&nbsp;return TRUE<Br>
}<Br>
</Br>
通过建立区域和调用SetWindowRgn,已经建立一个不规则形状的窗口,下面的例子程序是修改OnPaint函数使窗口形状看起来象一个球形体。<Br>
voik CRoundDlg : : OnPaint ( )<Br>
{<Br>
&nbsp;CPaintDC de (this)  // device context for painting<Br>
.<Br>
&nbsp;//draw ellipse with out any border<Br>
&nbsp;dc. SelecStockObject (NULL_PEN)<Br>
&nbsp;//get the RGB colour components of the sphere color<Br>
&nbsp;COLORREF color= RGB( 0 , 0 , 255)<Br>
&nbsp;BYTE byRed =GetRValue (color)<Br>
&nbsp;BYTE byGreen = GetGValue (color)<Br>
&nbsp;BYTE byBlue = GetBValue (color)<Br>
</Br>
&nbsp;// get the size of the view window<Br>
&nbsp;Crect rect<Br>
&nbsp;GetClientRect (rect)<Br>
</Br>
&nbsp;// get minimun number of units<Br>
&nbsp;int nUnits =min (rect.right , rect.bottom )<Br>
</Br>
&nbsp;//calculate he horiaontal and vertical step size<Br>
&nbsp;float fltStepHorz = (float) rect.right /nUnits<Br>
&nbsp;float fltStepVert = (float) rect.bottom /nUnits<Br>
</Br>
</Br>
&nbsp;int nEllipse = nUnits/3 // calculate how many to<Br>
draw<Br>
&nbsp;int nIndex<Br>
// current ellipse that is being draw<Br>
</Br>
&nbsp;CBrush brush<Br>
// bursh used for ellipse fill color<Br>
&nbsp;CBrush *pBrushOld // previous<Br>
brush that was selected into dc<Br>
&nbsp;//draw ellipse , gradually moving towards upper-right<Br>
corner<Br>
&nbsp;for (nIndex = 0  nIndes < + nEllipse  nIndes++)<Br>
{<Br>
&nbsp;//creat solid brush<Br>
&nbsp;brush . CreatSolidBrush (RGB ( ( (nIndex*byRed ) /nEllipse ).<Br>
( ( nIndex * byGreen ) /nEllipse ), ( (nIndex * byBlue)<Br>
/nEllipse ) ) )<Br>
</Br>
&nbsp;//select brush into dc<Br>
&nbsp;pBrushOld= dc .SelectObject (&brhsh)<Br>
</Br>
&nbsp;//draw ellipse<Br>
&nbsp;dc .Ellipse ( (int) fltStepHorz * 2, (int) fltStepVert * nIndex ,<Br>
&nbsp;rect. right -( (int) fltStepHorz * nIndex )+ 1,<Br>
&nbsp;rect . bottom -( (int) fltStepVert * (nIndex *2) ) +1)<Br>
</Br>
&nbsp;//delete the brush<Br>
&nbsp;brush.DelecteObject ( )<Br>
&nbsp;}<Br>
&nbsp;}<Br>
</Br>
最后,处理WM_NCHITTEST消息,使当击打窗口的任何位置时能移动窗口。<Br>
UINT CRoundDlg : : OnNchitTest (Cpoint point )<Br>
{<Br>
&nbsp;//Let user move window by clickign anywhere on thewindow .<Br>
&nbsp;UINT nHitTest = CDialog : : OnNcHitTest (point)<Br>
&nbsp;rerurn (nHitTest = = HTCLIENT)? HTCAPTION: nHitTest<Br>
</Br>
&nbsp;}<Br>
</Br>
</p></td></tr>
</table>
</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -