矩形和區域 2016-09-28 00:00:00 廣州睿豐德信息科技有限公司 閱讀 睿豐德科技 專注RFID識別技術和條碼識別技術與管理軟件的集成項目。質量追溯系統、MES系統、金蝶與條碼系統對接、用友與條碼系統對接 下面有三個繪圖函數需要一個指向矩形結構的指針: FillRect(hdc,&rect,hbursh);//填充 FrameRect(hdc,&rect,hbrush);//掏空 InvertRect(hdc,&rect);//內部取反 [cpp] view plaincopy 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] view plaincopy FillRgn(hdc,hrgn,hbrush); FrameRgn(hdc,hbrush,xFrame,yFrame); InvertRgn(hdc,hrgn); PaintRgn(hdc,hrgn); [cpp] view plaincopy DeleteObject(hrgn); [cpp] view plaincopy SelectObject(hdc,hrgn)=SelectClipRgn(hdc,hrgn); 使得矩形,區域有效和無效的函數 [cpp] view plaincopy InvalidateRect ValidateRect InvalidateRgn ValidateRgn 下面是簡單的例子: [cpp] view plaincopy 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; [cpp] view plaincopy hrgn=CreateRectRgn(xleft,ytop,xright,ybottom); hrgn=CreateRectRgnIndirect(&rect); hrgn=CreateEllipticRgn(xleft,ytop,xright,ybottom); hrgn=CreatePolygonRgn(&point,icount,ipolyFillMode); RFID管理系統集成商 RFID中間件 條碼系統中間層 物聯網軟件集成