VC---创建一个不规则形状的窗口
2008-01-23 10:56
633 查看
可以使用MFC 函数cWnd::SetWindowRgn。该函数将绘画和鼠标消息限定在窗口的一个指定
的区域,实际上使窗口成为指定的不规则形状。
使用AppWizard创建一个基于对的应用程序并使用资源编辑器从主对话资源中删
除所在的缺省控件、标题以及边界。给对话类增加一个CRgn 数据成员,以后要使用该
数据成员建立窗口区域。
BOOL CTest2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//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);
SetWindowRgn((HRGN)m_rgn,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest2Dlg::OnPaint()
{
CPaintDC dc (this) ; // device context for painting .
//draw ellipse with out any border
dc.SelectStockObject(NULL_PEN);
//get the RGB colour components of the sphere color
//COLORREF color= RGB( 0 , 0 , 255);
COLORREF color= RGB( 255 , 255, 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 to draw
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-right corner
for (nIndex = 0 ; nIndex <= nEllipse ; nIndex ++)
{
//creat solid brush
brush.CreateSolidBrush(RGB ( ( (nIndex *byRed ) /nEllipse ) ,
( ( nIndex * byGreen ) /nEllipse ), ( (nIndex * byBlue) /nEllipse ) ) );
//select brush into dc
pBrushOld= dc.SelectObject (&brush);
//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.DeleteObject ( );
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
UINT CTest2Dlg::OnNcHitTest(CPoint point)
{
// TODO: Add your message handler code here and/or call default
UINT nHitTest = CDialog::OnNcHitTest (point) ;
return (nHitTest == HTCLIENT)? HTCAPTION: nHitTest ;
// return CDialog::OnNcHitTest(point);
}
的区域,实际上使窗口成为指定的不规则形状。
使用AppWizard创建一个基于对的应用程序并使用资源编辑器从主对话资源中删
除所在的缺省控件、标题以及边界。给对话类增加一个CRgn 数据成员,以后要使用该
数据成员建立窗口区域。
BOOL CTest2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//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);
SetWindowRgn((HRGN)m_rgn,TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest2Dlg::OnPaint()
{
CPaintDC dc (this) ; // device context for painting .
//draw ellipse with out any border
dc.SelectStockObject(NULL_PEN);
//get the RGB colour components of the sphere color
//COLORREF color= RGB( 0 , 0 , 255);
COLORREF color= RGB( 255 , 255, 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 to draw
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-right corner
for (nIndex = 0 ; nIndex <= nEllipse ; nIndex ++)
{
//creat solid brush
brush.CreateSolidBrush(RGB ( ( (nIndex *byRed ) /nEllipse ) ,
( ( nIndex * byGreen ) /nEllipse ), ( (nIndex * byBlue) /nEllipse ) ) );
//select brush into dc
pBrushOld= dc.SelectObject (&brush);
//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.DeleteObject ( );
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
UINT CTest2Dlg::OnNcHitTest(CPoint point)
{
// TODO: Add your message handler code here and/or call default
UINT nHitTest = CDialog::OnNcHitTest (point) ;
return (nHitTest == HTCLIENT)? HTCAPTION: nHitTest ;
// return CDialog::OnNcHitTest(point);
}
相关文章推荐
- 如何创建一个不规则形状的窗口收藏
- 如何创建一个不规则形状的窗口
- VC创建不规则窗口
- 使用Win32 API创建不规则形状&带透明色的窗口
- VC创建自定义不规则窗口
- 【VC编程】笔记1--创建一个Win32的应用程序,并显示创建的窗口和菜单
- WindowsAPI_001:创建一个不规则的窗口的方法(用到Region系列API)
- VC++创建一个Windows窗口程序
- 如何实现一个不规则形状的WPF窗口
- 在QT中如何实现一个不规则形状的窗口
- VC++ game(四) 通过Windows API 来创建一个空窗口
- 创建不规则形状窗口
- VC 创建一个图标菜单
- [导入]创建一个没有窗口的程序
- OpenGL_Qt学习笔记之_01(创建一个OpenGL窗口)
- directX学习(1)创建一个空窗口
- NeHe_001_创建一个OpenGL窗口
- 这个例子演示了如何创建一个父窗口部件和子窗口部件。
- 如何创建一个用弹出窗口来查看详细信息的超链接列
- VC++中有关句柄和指针及其转换 1.MFC窗口的句柄和指针的转换 (1) 一般窗口对象都会有一个其对应的句柄变量,所以我们可以取此对象的m_hWnd属性来得到句柄。 (2)