您的位置:程序门 -> vc/mfc -> 界面



如何制作不规则形状按扭?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何制作不规则形状按扭?
发表于:2008-02-20 21:24:48 楼主
1.   如果继承自   cbutton   类的话,怎么修改按扭的形状?

2.   如果继承自   cwnd   类的话,可以实现么?
发表于:2008-02-20 21:40:471楼 得分:0
跟什么基类没有关系
看这篇文章
http://www.vckbase.com/document/viewdoc/?id=541
按钮什么的都是窗口,对按钮这样做即可.
发表于:2008-02-20 22:16:332楼 得分:0
各个控件都继承自cwnd,包括按纽.
发表于:2008-02-22 10:06:133楼 得分:0
但是重载后
setwindowrgn并不成功是何原因?
发表于:2008-02-22 16:02:304楼 得分:0
看看这个有用吗
可以使用新的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   ;
}  
发表于:2008-02-22 17:12:565楼 得分:0
可以用贴图的按钮   图标,bitmap等
效果就看美工的了


快速检索

最新资讯
热门点击