DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

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

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

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

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

  1. case WM_PAINT:  
  2.             hdc=BeginPaint(hwnd,&ps);  
  3.             //GetClientRect(hwnd,&rect);  
  4.               
  5.             //hrgn=CreateRectRgn(100,100,300,300);  
  6.             //hbrush=CreateSolidBrush(RGB(255,0,0));  
  7.             //FillRgn(hdc,hrgn,hbrush);  
  8.             //InvertRgn(hdc,hrgn);//取反  
  9.             //FrameRgn(hdc,hrgn,hbrush,0,0);  
  10.   
  11.               
  12.             r1.left=100;  
  13.             r1.top=100;  
  14.             r1.right=200;  
  15.             r1.bottom=200;  
  16.             hbrush=CreateSolidBrush(RGB(255,0,0));//创建画刷  
  17.             FillRect(hdc,&r1,hbrush);  
  18.   
  19.             r2.left=200;  
  20.             r2.top=100;  
  21.             r2.right=300;  
  22.             r2.bottom=200;  
  23.             FrameRect(hdc,&r2,hbrush);  
  24.   
  25.             r3.left=300;  
  26.             r3.top=100;  
  27.             r3.right=400;  
  28.             r3.bottom=200;  
  29.             InvertRect(hdc,&r3);  
  30.   
  31.             EndPaint(hwnd,&ps);  
  32.             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) 判断点是否在矩形内部

 

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

  1. FillRgn(hdc,hrgn,hbrush);  
  2. FrameRgn(hdc,hbrush,xFrame,yFrame);  
  3. InvertRgn(hdc,hrgn);  
  4. PaintRgn(hdc,hrgn);  
  1. DeleteObject(hrgn);  
  1. SelectObject(hdc,hrgn)=SelectClipRgn(hdc,hrgn);  

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

  1. InvalidateRect       ValidateRect  
  2. InvalidateRgn        ValidateRgn  

下面是简单的例子:

  1. case WM_PAINT:  
  2.             hdc=BeginPaint(hwnd,&ps);  
  3.             //GetClientRect(hwnd,&rect);  
  4.               
  5.             //hrgn=CreateRectRgn(100,100,300,300);  
  6.             //hbrush=CreateSolidBrush(RGB(255,0,0));  
  7.             //FillRgn(hdc,hrgn,hbrush);  
  8.             //InvertRgn(hdc,hrgn);//取反  
  9.             //FrameRgn(hdc,hrgn,hbrush,0,0);  
  10.   
  11.               
  12.             r1.left=100;  
  13.             r1.top=100;  
  14.             r1.right=200;  
  15.             r1.bottom=200;  
  16.             hbrush=CreateSolidBrush(RGB(255,0,0));//创建画刷  
  17.             //FillRect(hdc,&r1,hbrush);  
  18.   
  19.             r2.left=150;  
  20.             r2.top=100;  
  21.             r2.right=250;  
  22.             r2.bottom=200;  
  23.             //FrameRect(hdc,&r2,hbrush);  
  24.   
  25.             IntersectRect(&r3,&r1,&r2);//r1,r2矩形取交集,存放在r3  
  26.             FillRect(hdc,&r3,hbrush);  
  27.             flag=(int)IsRectEmpty(&r3);//判断矩形是否为空  
  28.             TextOut(hdc,300,300,szBuffer,wsprintf(szBuffer,TEXT("%d"),flag));  
  29.   
  30.             EndPaint(hwnd,&ps);  
  31.             return 0;  


  1. hrgn=CreateRectRgn(xleft,ytop,xright,ybottom);  
  2. hrgn=CreateRectRgnIndirect(&rect);  
  3. hrgn=CreateEllipticRgn(xleft,ytop,xright,ybottom);  
  4. hrgn=CreatePolygonRgn(&point,icount,ipolyFillMode);  
posted on   DoubleLi  阅读(935)  评论(0编辑  收藏  举报
编辑推荐:
· 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中导出类和对话框
点击右上角即可分享
微信分享提示