可以利用labwindows制作特殊图形的面板,比如圆形,椭圆,正方形等等。
制作步骤如下:
- 获取panel所在窗口句柄
DWND hwnd;
GetPanelAttribute(panel,control,ATTR_SYSTEM_HANDLE,(int*)&hwnd); - 获取标题栏高度
int titleLen=GetsyetemMetrics(SM_CYCAPTION); - 获得窗口大小
RECT FullRect;
GetWindowRect(hwnd,FullRect); - 获取客户区大小
RECT ClientRect;
GetClientRect(hwnd,ClientRect); - 制作特殊形状图形
A:椭圆:CreateEllipticRgn(left,top,right,bottom);
B:带圆角的长方形:CreateRoundRectRgn(left,top,right,bottom,angle,angle);
C:多边形区域:CreatePloygonRgn
D:可重叠多边形区域:CreatePloyPloygonRgn
D:合并两个区域CombineRgn(Dis,Sor1,Sor2,Mode);其中MODE有愈多选项,根据 不同选项得到结果不同
E:删除合并后其他区域的GDI: DeleteObject - 制作特殊区域 SetWindowRgn(hwnd,RECT rect,TURE);
GetPanelAttribute(panel,ATTR_SYSTEM_WINDOW_HANDLE,(int*)&hwnd);
GetPanelAttribute(panel,ATTR_TITLEBAR_VISIBLE,&titlebar);
if(titlebar)
{
TitlebarHeight=GetSystemMetrics(SM_CYCAPTION);
}
GetWindowRect(hwnd,&WindowRect);
GetClientRect(hwnd,&ClientRect);
fullheight=WindowRect.bottom-WindowRect.top;
fullwidth=WindowRect.right-WindowRect.left;
verticalborderwidth =(fullheight-TitlebarHeight-ClientRect.bottom)/2;
horizentalborderwidth=(fullwidth-ClientRect.right)/2;
ShapeRect.left=horizentalborderwidth;
ShapeRect.top=TitlebarHeight+verticalborderwidth;
ShapeRect.right=horizentalborderwidth+ClientRect.right;
ShapeRect.bottom=horizentalborderwidth+ClientRect.bottom+TitlebarHeight;
int arcvalue;
//以下绘制区域重复,实际代码中任选其一
//绘制椭圆区域 winrgn=CreateEllipticRgn(ShapeRect.left,ShapeRect.top,ShapeRect.right,ShapeRect.bottom);
SetWindowRgn(hwnd,winrgn,1);
//绘制圆角矩形区域
GetCtrlVal(panel,PANEL_NUMERICGAUGE,&arcvalue);
winrgn=CreateRoundRectRgn(ShapeRect.left,ShapeRect.top,ShapeRect.right,
ShapeRect.bottom,arcvalue,arcvalue);
SetWindowRgn(hwnd,winrgn,TRUE);
//绘制两个圆合并区域
GetCtrlVal(panel,PANEL_NUMERICGAUGE,&arcvalue);
winrgn=CreateEllipticRgn(ShapeRect.left,ShapeRect.top,ShapeRect.bottom,ShapeRect.right);
innerrgn=CreateEllipticRgn(ShapeRect.left+arcvalue,ShapeRect.top+arcvalue,
ShapeRect.bottom-arcvalue,ShapeRect.right-arcvalue);
CombineRgn(winrgn,winrgn,innerrgn,RGN_DIFF);
DeleteObject(innerrgn);
SetWindowRgn(hwnd,winrgn,TRUE);