如何做出不规则边框的MDI程序 我需要把 MDI 程序的边框画上不规则的图形 做为边框,请问 怎么 做 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 创建一个不规则形状的窗口 可以使用新的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 borderdc. SelecStockObject (NULL_PEN);//get the RGB colour components of the sphere colorCOLORREF color= RGB( 0 , 0 , 255);BYTE byRed =GetRValue (color);BYTE byGreen = GetGValue (color);BYTE byBlue = GetBValue (color);// get the size of the view windowCrect rect ;GetClientRect (rect);// get minimun number of unitsint nUnits =min (rect.right , rect.bottom );//calculate he horiaontal and vertical step sizefloat fltStepHorz = (float) rect.right /nUnits ;float fltStepVert = (float) rect.bottom /nUnits ;int nEllipse = nUnits/3; // calculate how many to drawint nIndex ; // current ellipse that is being drawCBrush brush ; // bursh used for ellipse fill colorCBrush *pBrushOld; // previous brush that was selected into dc//draw ellipse , gradually moving towards upper-right cornerfor (nIndex = 0 ; nIndes < + nEllipse ; nIndes ++){//creat solid brushbrush . CreatSolidBrush (RGB ( ( (nIndex *byRed ) /nEllipse ) ,( ( nIndex * byGreen ) /nEllipse ), ( (nIndex * byBlue) /nEllipse ) ) );//select brush into dcpBrushOld= dc .SelectObject (&brhsh);//draw ellipsedc .Ellipse ( (int) fltStepHorz * 2, (int) fltStepVert * nIndex ,rect. right -( (int) fltStepHorz * nIndex )+ 1,rect . bottom -( (int) fltStepVert * (nIndex *2) ) +1) ;//delete the brushbrush.DelecteObject ( );}}最后,处理WM_NCHITTEST消息,使当击打窗口的任何位置时能移动窗口。UINT CRoundDlg : : OnNchitTest (Cpoint point ){//Let user move window by clickign anywhere on the window .UINT nHitTest = CDialog : : OnNcHitTest (point) ;rerurn (nHitTest = = HTCLIENT)? HTCAPTION: nHitTest ;} 单一窗口没问题,mdi的窗口不太好说了,没试过。 是MDI程序, 不是对话框程序 BCG到是实现了,可是他的方法太复杂。 MFC的DLL还是不懂 push_back出错!为什么? 成员函数的调用问题 DDERR_CANTCREATEDC 模拟用户输入的问题 怎么得到directshow中filter的CLSID? 关于RAS。。。在先等待。。。。200分 超级菜鸟的问题:给一个静态文本设标题,怎么做! 请问高手:如何开两个窗口,一个放所有按钮等,另一个只显示图形? 高手请答 如何使用CFileDialog类。 求救数据库中的输出问题! 如何实现锁定解锁工具栏的功能,顶者有分
可以使用新的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 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 ; 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 the window .
UINT nHitTest = CDialog : : OnNcHitTest (point) ;
rerurn (nHitTest = = HTCLIENT)? HTCAPTION: nHitTest ;
}