下面有三个绘图函数需要一个指向矩形结构的指针:
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);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2012-11-23 MFC应用程序框架入门
2012-11-23 全面解析MFC应用程序框架
2012-11-23 VC Debug 小技巧——伪符号
2012-11-23 VC下用MFC类实现网络编程
2012-11-23 MFC中消息循环处理的几个函数之间的区别
2012-11-23 MFC中自由使用自定义消息
2012-11-23 实现MFC扩展DLL中导出类和对话框