欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

win32 各种形状api

程序员文章站 2022-07-05 12:58:58
...

1.Rectangle //绘制矩形

BOOL Rectangle(
int x1,
int y1,
int x2,
int y2
);
BOOL Rectangle(
LPCRECT lpRect
);
Rectangle(hdc,int left,int top,int rigth,int buttom);

2.Ellipse //椭圆
BOOL Rectangle(
int x1,
int y1,
int x2,
int y2
);
BOOL Rectangle(
LPCRECT lpRect
);
Ellipse(HDC hdc,int left,int top,int right,int buttom);
返回值 成功非零 否则为0.

3.RoundRect //带圆角的矩形

  BOOL RoundRect(

int x1,
int y1,
int x2,
int y2,
int x3,
int y3
);
BOOL RoundRect(
LPCRECT lpRect,
POINT point
);
RoundRect(HDC hdc,int left ,int top,int right , int buttom ,int weight ,int Hight);
成功非0,否则为0.

4.Arc //弧
BOOL Arc(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int x4,
int y4
);
BOOL Arc(
LPCRECT lpRect,
POINT ptStart,
POINT ptEnd
);
Arc(HDC hdc,int left,int top,int right,int buttom ,int x3,int y3,int x4,int y4 );
(x3,y3)为起始点 ,(x4,y4)为终点(并不一定在弧上)。
弧不封闭。

5.Chord //带弦弧
BOOL Chord(
int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int x4,
int y4
);
BOOL Chord(
LPCRECT lpRect,
POINT ptStart,
POINT ptEnd
);
参数和Arc相同 ,比Arc多一条弦,构成封闭图形。

6.Pie //扇形

  BOOL Pie(

int x1,
int y1,
int x2,
int y2,
int x3,
int y3,
int x4,
int y4
);
BOOL Pie(
LPCRECT lpRect,
POINT ptStart,
POINT ptEnd
);
参数和Arc,Chord相同,由弧和起始线加终线构成封闭图形。

举例:

case WM_PAINT:
        hdc = BeginPaint(hwnd, &ps);

        //矩形
        Rectangle(hdc, cxClient / 4, cyClient / 4, cxClient * 3 / 4, cyClient * 3 / 4); 
        //椭圆
        Ellipse(hdc, cxClient / 4, cyClient / 4, cxClient * 3 / 4, cyClient * 3 / 4);    
        //棱角为弧的矩形
        RoundRect(hdc, cxClient / 4, cyClient / 4, cxClient * 3 / 4, cyClient * 3 / 4, cxClient / 8, cyClient / 8);     
        //弧
        Arc(hdc, cxClient / 4, cyClient / 4, cxClient * 3 / 4, cyClient * 3 / 4,cxClient/2,0,0,cyClient/2);      
        //带弦弧
        Chord(hdc, cxClient / 4, cyClient / 4, cxClient * 3 / 4, cyClient * 3 / 4, cxClient / 2, 0, 0, cyClient / 2);
        //扇形
        Pie(hdc, cxClient / 4, cyClient / 4, cxClient * 3 / 4, cyClient * 3 / 4, cxClient / 2, 0, 0, cyClient / 2);

        EndPaint(hwnd, &ps);
        return 0;