矩形和区域
下面有三个绘图函数需要一个指向矩形结构的指针:
FillRect(hdc,&rect,hbursh);//填充
FrameRect(hdc,&rect,hbrush);//掏空
InvertRect(hdc,&rect);//内部取反
[cpp]
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;
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) 判断点是否在矩形内部
区域跟矩形一样,有以下四个绘图函数
[cpp]
FillRgn(hdc,hrgn,hbrush);
FrameRgn(hdc,hbrush,xFrame,yFrame);
InvertRgn(hdc,hrgn);
PaintRgn(hdc,hrgn);
FillRgn(hdc,hrgn,hbrush);
FrameRgn(hdc,hbrush,xFrame,yFrame);
InvertRgn(hdc,hrgn);
PaintRgn(hdc,hrgn);[cpp] view plaincopyprint?DeleteObject(hrgn);
DeleteObject(hrgn);[cpp] view plaincopyprint?SelectObject(hdc,hrgn)=SelectClipRgn(hdc,hrgn);
SelectObject(hdc,hrgn)=SelectClipRgn(hdc,hrgn);使得矩形,区域有效和无效的函数
[cpp]
InvalidateRect ValidateRect
InvalidateRgn ValidateRgn
InvalidateRect ValidateRect
InvalidateRgn ValidateRgn下面是简单的例子:
[cpp]
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);
Intersect
补充:软件开发 , C++ ,