| 发表于: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 ; } | | |
|