矩形和区域

下面有三个绘图函数需要一个指向矩形结构的指针:

FillRect(hdc,&rect,hbursh);//填充

FrameRect(hdc,&rect,hbrush);//掏空

InvertRect(hdc,&rect);//内部取反

case WM_PAINT:
			hdc=BeginPaint(hwnd,&ps);
			//GetClientRect(hwnd,&rect);
			
			//hrgn=CreateRectRgn(100,100,300,300);
			//hbrush=CreateSolidBrush(RGB(255,0,0));
			//FillRgn(hdc,hrgn,hbrush);
			//InvertRgn(hdc,hrgn);//取反
			//FrameRgn(hdc,hrgn,hbrush,0,0);

			
			r1.left=100;
			r1.top=100;
			r1.right=200;
			r1.bottom=200;
			hbrush=CreateSolidBrush(RGB(255,0,0));//创建画刷
			FillRect(hdc,&r1,hbrush);

			r2.left=200;
			r2.top=100;
			r2.right=300;
			r2.bottom=200;
			FrameRect(hdc,&r2,hbrush);

			r3.left=300;
			r3.top=100;
			r3.right=400;
			r3.bottom=200;
			InvertRect(hdc,&r3);

			EndPaint(hwnd,&ps);
			return 0;

下面还有八个关于矩形的操作:

OffsetRect(&rect,x,y)将矩形移动
InflateRect(&rect,x,y)增大缩小矩形的尺寸
SetRectEmpty(&rect)把矩形结构各字段设置为0
CopyRect(&DestRect,&ScrRect)将一个矩形结构复制到另一个矩形结构
IntersectRect(&destRect,&SrcRect1,&SrcRect2)获取两个矩形的交集
UnionRect(&DestRect,&SrcRect1,&SrcRect2)获取两个矩形的并集
bEmpty=IsRectEmpty(&Rect)判断矩形是否为空
bInRect=PtInRect(&rect,point)判断点是否在矩形内部

区域跟矩形一样,有以下四个绘图函数

FillRgn(hdc,hrgn,hbrush);
FrameRgn(hdc,hbrush,xFrame,yFrame);
InvertRgn(hdc,hrgn);
PaintRgn(hdc,hrgn);
DeleteObject(hrgn);
SelectObject(hdc,hrgn)=SelectClipRgn(hdc,hrgn);

使得矩形,区域有效和无效的函数

InvalidateRect       ValidateRect
InvalidateRgn        ValidateRgn

下面是简单的例子:

case WM_PAINT:
			hdc=BeginPaint(hwnd,&ps);
			//GetClientRect(hwnd,&rect);
			
			//hrgn=CreateRectRgn(100,100,300,300);
			//hbrush=CreateSolidBrush(RGB(255,0,0));
			//FillRgn(hdc,hrgn,hbrush);
			//InvertRgn(hdc,hrgn);//取反
			//FrameRgn(hdc,hrgn,hbrush,0,0);

			
			r1.left=100;
			r1.top=100;
			r1.right=200;
			r1.bottom=200;
			hbrush=CreateSolidBrush(RGB(255,0,0));//创建画刷
			//FillRect(hdc,&r1,hbrush);

			r2.left=150;
			r2.top=100;
			r2.right=250;
			r2.bottom=200;
			//FrameRect(hdc,&r2,hbrush);

			IntersectRect(&r3,&r1,&r2);//r1,r2矩形取交集,存放在r3
			FillRect(hdc,&r3,hbrush);
			flag=(int)IsRectEmpty(&r3);//判断矩形是否为空
			TextOut(hdc,300,300,szBuffer,wsprintf(szBuffer,TEXT("%d"),flag));

			EndPaint(hwnd,&ps);
			return 0;


hrgn=CreateRectRgn(xleft,ytop,xright,ybottom);
hrgn=CreateRectRgnIndirect(&rect);
hrgn=CreateEllipticRgn(xleft,ytop,xright,ybottom);
hrgn=CreatePolygonRgn(&point,icount,ipolyFillMode);





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值